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

[CoAP] Exposing multiple Things on the same Servient produces an Error #1193

Closed
FadySalama opened this issue Dec 15, 2023 · 2 comments · Fixed by #1195
Closed

[CoAP] Exposing multiple Things on the same Servient produces an Error #1193

FadySalama opened this issue Dec 15, 2023 · 2 comments · Fixed by #1195
Assignees
Labels
binding-coap Issues related to coap protocol binding bug Something isn't working

Comments

@FadySalama
Copy link
Contributor

FadySalama commented Dec 15, 2023

When I try to add multiple CoAP devices to the same servient defined like this

const coapServient = new Servient()
coapServient.addServer(new CoapServer({
    port: 5683
}))

it causes this error to occur

Error: getsockname EBADF
    at Socket.address (node:dgram:775:11)
    at CoapServer.getPort (/node_modules/@node-wot/binding-coap/dist/coap-server.js:104:27)
    at CoapServer.<anonymous> (/node_modules/@node-wot/binding-coap/dist/coap-server.js:112:31)
    at Generator.next (<anonymous>)
    at /node_modules/@node-wot/binding-coap/dist/coap-server.js:31:71
    at new Promise (<anonymous>)
    at __awaiter (/node_modules/@node-wot/binding-coap/dist/coap-server.js:27:12)
    at CoapServer.expose (/node_modules/@node-wot/binding-coap/dist/coap-server.js:111:16)
    at /node_modules/@node-wot/core/dist/servient.js:51:40
    at Array.forEach (<anonymous>) {
  errno: -9,
  code: 'EBADF',
  syscall: 'getsockname'
}

The error does not happen if I expose only 1 CoAP device and only happens with CoAP. (I run the same code to generate HTTP instances as well and it works flawlessly). I was able to replicate the error in a Windows environment and in a dockerized Ubuntu environment running an Ubuntu host.

@relu91 relu91 added bug Something isn't working binding-coap Issues related to coap protocol binding labels Dec 15, 2023
@JKRhb JKRhb self-assigned this Dec 17, 2023
@FadySalama
Copy link
Contributor Author

FadySalama commented Dec 18, 2023

A small update: I found what was causing this issue. I was calling servient.start() for each new device added to get the WoT object which did break things severely for CoAP and not so severely for HTTP. By calling servient.start() only once, the issues were solved and I could add multiple CoAP devices without any issues.
The problem is, there is nothing stopping me from calling servient.start() multiple times. How about ensuring that calling servient.start() always returns exactly one WoT object using a singleton pattern? Otherwise, I think it is safe to close this issue.

@danielpeintner
Copy link
Member

I opened #1195 which prevents a Servient to be started a second time.

Hence in your case you would get an error ("Servient started already") the second time.
Does this make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-coap Issues related to coap protocol binding bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants