n-thumann / IPTV-ReStream

An app to forward source specific multicast streams via HTTP
BSD 3-Clause "New" or "Revised" License
103 stars 36 forks source link

Set Receiver Socket Timeout when No Data is Received #199

Open barlowd55 opened 1 year ago

barlowd55 commented 1 year ago

I use an encoder that streams on the multicast port which is consumed through your app and re-streams to customers.

There is one issue I faced. Sometimes the source on the encoder may be down. The port may be active but does not send any data.

When such an instance happens, the app goes in an infinite loop to receive the data on the port.

Is there a possibility to set a timeout on the receiver to close the connection for the client, instead of looping continuously.

n-thumann commented 1 year ago

Thank you for your suggestion! Sounds like a good idea to me. What do you think a reasonable timeout would be? Maybe 30 seconds?

n-thumann commented 1 year ago

@barlowd55 do you want to give #200 a try? 😊

barlowd55 commented 1 year ago

Thanks for the feature. I tried out the timeout option, but what I can see is that the client does not disconnect. It just keeps on trying to establish a connection and the app simply disconnects the connection.

My client app keeps polling trying to establish a connection but does not close the connection. Eventually the client times out with 500 error.

Is there a possibility to close the client connection, maybe by sending the correct header code or by calling the socket close function.

barlowd55 commented 1 year ago

Commenting on the same issue, this is the error I get on console:

(node:877710) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:530:11)
    at ServerResponse.header (/root/restream/node_modules/express/lib/response.js:794:10)
    at ServerResponse.contentType (/root/restream/node_modules/express/lib/response.js:624:15)
    at ServerResponse.send (/root/restream/node_modules/express/lib/response.js:149:14)
    at /root/restream/dist/routes/live.js:38:25
(node:877710) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:877710) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Not sure, but after some time, the code exists node app.

vuducdong commented 2 months ago

How to fix this error? @n-thumann

Error: Failed to lookup view "stations" in views directory "/views"
    at Function.render (/app/node_modules/express/lib/application.js:597:17)
    at ServerResponse.render (/app/node_modules/express/lib/response.js:1039:7)
    at /app/routes/station.js:13:9
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/app/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/app/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at /app/node_modules/express/lib/router/index.js:284:15
    at Function.process_params (/app/node_modules/express/lib/router/index.js:346:12)
    at next (/app/node_modules/express/lib/router/index.js:280:10)

or

Error: Failed to lookup view "status" in views directory "/views"
    at Function.render (/app/node_modules/express/lib/application.js:597:17)
    at ServerResponse.render (/app/node_modules/express/lib/response.js:1039:7)
    at /app/routes/status.js:11:9
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/app/node_modules/express/lib/router/route.js:144:13)
    at Route.dispatch (/app/node_modules/express/lib/router/route.js:114:3)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at /app/node_modules/express/lib/router/index.js:284:15
    at Function.process_params (/app/node_modules/express/lib/router/index.js:346:12)
    at next (/app/node_modules/express/lib/router/index.js:280:10)

Thanks!

n-thumann commented 2 months ago

Is is possible that you're running an outdated version of IPTV-ReStream? This is a known issue (https://github.com/n-thumann/IPTV-ReStream/issues/238), but I've fixed it in https://github.com/n-thumann/IPTV-ReStream/releases/tag/v1.5.0.

vuducdong commented 2 months ago

Is is possible that you're running an outdated version of IPTV-ReStream? This is a known issue (#238), but I've fixed it in https://github.com/n-thumann/IPTV-ReStream/releases/tag/v1.5.0.

ok, it's my fault, I got the source from docker hub (still not updated to the latest version)

image

But my ISP provide iptv through vlan, so here just format is needed, for example: rtp://@232.84.1.117:10254

is there to watch live

image

while the multicastadressliste.json file requires media_multicast_sourceip to be filled in.

Can I customize?

For example, with updxy, I'm watching live like this image

Thank you so much and Have a nice day!

n-thumann commented 2 months ago

But my ISP provide iptv through vlan, so here just format is needed, for example: rtp://@232.84.1.117:10254

VLANs are beyond the control of an application. Looks are you have a RTP multicast address, but without a specific source.

while the multicastadressliste.json file requires media_multicast_sourceip to be filled in. Can I customize?

For the missing multicast source IP, one option would be to figure out (e.g. by inspecting the traffic with Wireshark) what the actual source IP is and use that one. If that's not possible, feel free to adjust the code in a fork. For my side, I would prefer to keep the source IP mandatory, because this app is intended for source specific multicast :)

vuducdong commented 2 months ago

But my ISP provide iptv through vlan, so here just format is needed, for example: rtp://@232.84.1.117:10254

VLANs are beyond the control of an application. Looks are you have a RTP multicast address, but without a specific source.

while the multicastadressliste.json file requires media_multicast_sourceip to be filled in.

Can I customize?

For the missing multicast source IP, one option would be to figure out (e.g. by inspecting the traffic with Wireshark) what the actual source IP is and use that one.

If that's not possible, feel free to adjust the code in a fork. For my side, I would prefer to keep the source IP mandatory, because this app is intended for source specific multicast :)

Ok, thank you for your support.