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

Calling HttpServer's stop method in binding-http returns nothing #1237

Open
hidetak opened this issue Feb 13, 2024 · 3 comments
Open

Calling HttpServer's stop method in binding-http returns nothing #1237

hidetak opened this issue Feb 13, 2024 · 3 comments
Labels
binding-http Issues related to http protocol binding

Comments

@hidetak
Copy link
Contributor

hidetak commented Feb 13, 2024

The following problem occurred. I apologize for the inconvenience and would appreciate your confirmation.
I would appreciate it if you could tell me if I am calling it the wrong way, etc.

Problem

Nothing is returned when I call the stop method of HttpServer of Binding-http.
This problem may occur if the property is being observed from the client.

environment

  • Mac(Apple siicon)
  • OS: Sonoma 14.1
  • nodejs: v18 or v20
  • node-wot: 0.8.12

Steps to reproduce

get the following code

https://github.com/hidetak/test-node-wot/tree/main/no-stop-httpserver

  1. $ npm install
  2. $ npm run start:server
  3. open new terminal
  4. $ npm run start:client
  5. After 10 seconds have elapsed since the server was started, the termination process begins (The following text will appear in the terminal where the server is run)
[debug] endServient called.
[debug] server destroyed.

If 3 and 4 are not performed, the following is displayed and appears to be correctly terminated.

[debug] endServient called.
[debug] server destroyed.
[debug] server stopped.
[debug] servient shutdown.
@danielpeintner danielpeintner added the binding-http Issues related to http protocol binding label Feb 13, 2024
@danielpeintner
Copy link
Member

I quickly checked and I would like to make 2 additions

  • if testing the client, you need to change the IP address in example-client.ts from 192.168.0.247 to localhost (or something else that works for you)
  • you don't need the client, just fetching the TD in the browser via http://localhost:8080/mycounter right after the server is started is enough

It seems something is blocking the server to stop immediately.

Activating the debug log we run into the the following

[debug] endServient called.
  node-wot:binding-http:http-server:debug HttpServer on port 8080 destroying thingId 'urn:uuid:ff9d8288-9458-4c10-adfd-e209facce331' +10s
  node-wot:binding-http:http-server:info HttpServer successfully destroyed 'MyCounter' +10s
[debug] server destroyed.
  node-wot:binding-http:http-server:info HttpServer stopping on port 8080 +1ms

afterwards hanging.

Wait.. there seems to be a timeout... after a while we get

[debug] server stopped.
  node-wot:binding-http:http-server:info HttpServer stopping on port -1 +2m
[debug] servient shutdown.

@hidetak can you confirm that the server stops after ~2 minutes also?

@hidetak
Copy link
Contributor Author

hidetak commented Feb 13, 2024

@danielpeintner

Thank you for your confirmation.

if testing the client, you need to change the IP address in example-client.ts from 192.168.0.247 to localhost (or something else that works for you)

I apologize for the inconvenience of the IP address in the ThingDescription not being set to localhost, and I have placed the client with the IP address changed to localhost below.
https://github.com/hidetak/test-node-wot/blob/main/no-stop-httpserver/src/example-client.ts

you don't need the client, just fetching the TD in the browser via http://localhost:8080/mycounter right after the server is started is enough

As you said, the same phenomenon was placed not from the client but from the browser.

@hidetak can you confirm that the server stops after ~2 minutes also?

When accessed through a browser, the process took approximately 5 minutes.
However, when accessed from the client, it did not finish even after 10 minutes.

When deploying a flow in Node-RED, we restart the server.
If it takes several minutes to deploy a flow, is it possible to shorten the time because it is inefficient for flow development?
(I now have a 10 second timeout in the Node-RED node implementation, but I'm not sure if it is terminating correctly.)

@danielpeintner
Copy link
Member

I think it is not really us preventing to close the connection but there may be somehow "alive" connections that keep the server up.

There are very old threads like this or others like nodejs/node#2642 and people providing additions/code like here or a library-a / library-b / library-c for it or socket closing.

@relu91 any opinion/suggestion since you might be more familiar with this part of the code..

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