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

Fix #925 Memory Leak while WebSocketServerHandshakeException or Channel failed #926

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

HashJang
Copy link

@HashJang HashJang commented Jul 28, 2023

fix #925

}
}
try {
TimeUnit.SECONDS.sleep(3);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid this sleep call? Don't want to have sleeping threads

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok

@HashJang HashJang requested a review from mrniko July 28, 2023 05:51
public ClientsBox() {
scheduledExecutorService.scheduleWithFixedDelay(() -> {
List<UUID> disconnected = new ArrayList<>();
for (Map.Entry<UUID, ClientHead> entry : uuid2clients.entrySet()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace it with stream() ?

private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

public ClientsBox() {
scheduledExecutorService.scheduleWithFixedDelay(() -> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a periodical task for this and schedule this check after client connection?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid there would be bugs in future commit that cause this is not dereferenced after client disconnected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like the one this PR fix, we cannot confirm there would not be any bugs alike in the future. but we should not let this kind of bug cause Memory Leak. We should actively detect that, remove that and warn it by log

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic should be implemented in com.corundumstudio.socketio.handler.ClientHead#onChannelDisconnect() method without ScheduledExecutorService usage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic should be implemented in com.corundumstudio.socketio.handler.ClientHead#onChannelDisconnect() method without ScheduledExecutorService usage.

but like the bug this time, onChannelDisconnect is called indeed(due to scheduled ping timeout), but the namespaceClients does not contain the client which throw WebSocketException, which result in the uuid2clients does not remove it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're checking entry.getValue().isConnected() but it can be set only in onChannelDisconnect() handler. I suggest to call clientsBox.removeClient() in this method

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HashZhang

private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

public ClientsBox() {
scheduledExecutorService.scheduleWithFixedDelay(() -> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic should be implemented in com.corundumstudio.socketio.handler.ClientHead#onChannelDisconnect() method without ScheduledExecutorService usage.

@HashJang
Copy link
Author

HashJang commented Aug 4, 2023

this logic should be implemented in com.corundumstudio.socketio.handler.ClientHead#onChannelDisconnect() method without ScheduledExecutorService usage.

but like the bug this time, onChannelDisconnect is called indeed(due to scheduled ping timeout), but the namespaceClients does not contain the client which throw WebSocketException, which result in the uuid2clients does not remove it.

however, i cannot complain if you stick that this is not required, i can still remove it and keep the memory leak fixed, first thing first
@mrniko

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

Successfully merging this pull request may close these issues.

Memory Leak while WebSocketServerHandshakeException or Channel failed
2 participants