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

client.subscribe() keeps creating new connections #7

Open
Fishdrowned opened this issue Jul 21, 2017 · 6 comments
Open

client.subscribe() keeps creating new connections #7

Fishdrowned opened this issue Jul 21, 2017 · 6 comments

Comments

@Fishdrowned
Copy link

I see this in Chome devtool >> Network:
image

Client script:

<script src="../hprose/hprose-html5-2.0.34.js"></script>
<script type="text/javascript">
    !function () {
        var url = 'ws://127.0.0.1:2080/hello',
            subscriber = new hprose.WebSocketClient(url);
        subscriber.subscribe('push', function () {
            console.log(arguments);
        });
    }();
</script>

Server script:

use Hprose\Swoole\Server as Server;

$listen = 'ws://0.0.0.0:2080/hello';
$server = new Server($listen);
$server->publish('push');
$server->start();
@Fishdrowned
Copy link
Author

Fishdrowned commented Jul 21, 2017

It keeps creating new connections about every 30 seconds.

I can see the call stack by hanging mouse over the Initiator.

The first connection, looks OK, it was initiated by subscribe():
image

The second connection, no good:
image

The third connection, wow, look at the scroll bar, it gets longer:
image

@andot
Copy link
Member

andot commented Jul 21, 2017

because the client default timeout is 30s, and the server default timeout is 120s. you can set the client timeout more than 120s to fixed problem.

@Fishdrowned
Copy link
Author

Thank you for your reply, I've extended the client timeout to 1 day, it stops creating new connections.

But look at the 1st screenshot, it indicates that the old connections are not closed (status = 101 and time = Pending means the connection is still alive), but new connections are created.

PS. The term heartbeat is misleading, I expected it to send some ping frames to the client to keep connection open.

@andot
Copy link
Member

andot commented Jul 22, 2017

When timeout on client, the connection will not to be closed, because maybe some other requests on this connection too.

@Fishdrowned
Copy link
Author

The problem is, by default settings, client.subscribe() will keep creating connections as time grows, keep them open, not reusable, never closed, just like memory leak.

I guess this should be a architecture issue, but I don't have enough time to investigate and prove this.

Sets the client timeout to 1 day or some big number is just a workaround.

I implemented a manual but real heartbeat in my application, by pushing an empty string to the subscribers every minute.

@andot
Copy link
Member

andot commented Jul 30, 2017

Yes, you are right. I will try to fix this problem in next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants