wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

The problem of push_stream_channels_statistics #259

Closed kavin027 closed 7 years ago

kavin027 commented 7 years ago

First, I start a subscriber by curl -s -v 'http://localhost/sub/my_channel_1' on a mobile phone. I got stat messages ( curl -s -v 'http://localhost/channels-stats?id=my_channel_1') {"channel": "my_channel_1", "published_messages": 0, "stored_messages": 0, "subscribers": 1}

Then I tune my mobile phone into a flight mode (disconnect the network) I expected that subscribers should be 0. However, I still got stat messages ( curl -s -v 'http://localhost/channels-stats?id=my_channel_1') {"channel": "my_channel_1", "published_messages": 0, "stored_messages": 0, "subscribers": 1}

Please help me! Thank you!

wandenberg commented 7 years ago

@kavin027 the end of connection takes some time to be detected when it is not properly closed like the test you did. The server do not detect its termination immediately. A good practice is to set the ping message interval to a short value (according with you application needs, how fast you want to detect the client has disconnected) and a not so big socket output buffer. This way the server will periodically tries to write messages to each subscriber and at some point it will receives an error indicating that the client is no longer there and closes the connection at the server side, counting down the number of subscribers.