Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events without subprotocol might be causing unexpected behaviour #1281

Closed
VigneshVSV opened this issue May 2, 2024 · 3 comments
Closed

events without subprotocol might be causing unexpected behaviour #1281

VigneshVSV opened this issue May 2, 2024 · 3 comments
Labels
binding-http Issues related to http protocol binding

Comments

@VigneshVSV
Copy link

VigneshVSV commented May 2, 2024

I use events primarily with HTTP SSE.

When I generate the TD without the subprotocol option within the event affordance, the node-wot client subscribes to the event multiple times.

The event afffordance (faulty) schema is as follows:

intensity_measurement_event": {
      "forms": [
        {
          "href": "https://LAPTOP-F60CU35D:8083/spectrometer/ocean-optics/USB2000-plus/intensity/measurement-event",
          "op": "subscribeevent",
          "htv:methodName": "GET",
          "contentType": "text/event-stream"
        }
      ]
    }

The validator does not complain. When the client tries to subscribe to the event:

 spectrometer.subscribeEvent("intensity_measurement_event", async(data : InteractionOutput) => {
 const value = await data.value()
 console.log("event", value, data)            
 }).then((subscription : any) => {
     intensityMeasurementEvent = subscription 
     console.debug("subscribed to intensity measurement event")
 })

This somehow leads to 6 event subscriptions to the server side. I get the following output:

App.svelte:37 consumed thing description from spectrometer
App.svelte:43 updating state
App.svelte:59 action with value InteractionOutput {form: {}, schema: undefined, dataUsed: false}
App.svelte:60 action with value undefined
MainView.svelte:45 subscribed to intensity measurement event
MainView.svelte:42 event undefined InteractionOutput {form: {}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {}, schema: undefined, dataUsed: false}
MainView.svelte:42 event undefined InteractionOutput {form: {}, schema: undefined, dataUsed: false}
App.svelte:77 rescheduling property polling function

From server side:

count 42
DEBUG    - 2024-05-02T20:29:03:171 - spectrometer/ocean-optics/USB2000-plus - starting measurement count 43
DEBUG    - 2024-05-02T20:29:03:172 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:173 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:174 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:175 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:175 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:03:176 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:182 - spectrometer/ocean-optics/USB2000-plus - measurement taken at 02.05.2024 20:29:04.182 - measurement count 43
DEBUG    - 2024-05-02T20:29:04:184 - spectrometer/ocean-optics/USB2000-plus - starting measurement count 44
DEBUG    - 2024-05-02T20:29:04:185 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:186 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:187 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:188 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:188 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:04:189 - HTTPServer|0.0.0.0:8083 - new data sent - intensity-measurement-event
DEBUG    - 2024-05-02T20:29:05:196 - spectrometer/ocean-optics/USB2000-plus - measurement taken at 02.05.2024 20:29:05.196 - measurement count 44

The event is being sent, but there are 6 of them (each line claiming "new data sent" is a single event of same type). Also, I am not able to invoke further actions.

When adding the subprotocol field, the issue is solved. However, due to absence of schema the event value is undefined.
(#1280)

The TD document also says subprotocol is optional, may I know what is the default value?

@relu91 relu91 added the binding-http Issues related to http protocol binding label May 9, 2024
@relu91
Copy link
Member

relu91 commented May 9, 2024

By default, http-binding assumes any "event-like" affordance to be implemented with a long polling protocol. I bet that's the reason why you were seeing such weird behavior with multiple subscriptions ( the client continuously creates a GET request against the endpoint). To be honest I'm not sure how to properly solve this behaviour. What about adding a warning message? Something like: No subprotocol found defaulting to longpoll.

@VigneshVSV
Copy link
Author

VigneshVSV commented May 9, 2024

Yes sure.

Personally I would say that if there is more than one form of subprotocol possible with the same http method and URL, then subprotocol field can be made mandatory.

But of course, the warning would solve the issue of "unexpectedness"/unknown behaviour which makes the user dig deep into docs.

@VigneshVSV
Copy link
Author

I changed my mind. I think its fine if you just add a warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-http Issues related to http protocol binding
Projects
None yet
Development

No branches or pull requests

2 participants