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
[JENKINS-70103] Clear websocket sessions on connection close or error #7406
Conversation
This is causing a memory leak, as sessions pile up there and the GC does not collect them. See [JENKINS-70103](https://issues.jenkins.io/browse/JENKINS-70103) for more information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine so far as it goes but you are leaving
private static final Map<Listener, Session> sessions = Collections.synchronizedMap(new WeakHashMap<>()); |
HashMap
or IdentityHashMap
for clarity; or it does not, in which case the bug has not been explained.
@@ -147,6 +147,7 @@ public void onWebSocketText(String message) { | |||
@Override | |||
public void onWebSocketClose(int statusCode, String reason) { | |||
listener.onWebSocketClose(statusCode, reason); | |||
sessions.remove(listener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you know this will be called before
jenkins/websocket/jetty10/src/main/java/jenkins/websocket/Jetty10Provider.java
Lines 99 to 100 in 77c2450
public void close() throws IOException { | |
session().close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. Do you have some insight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. You would need to test it.
Then cease use of Ideally we could reproduce this, say in |
The problem is
get/setAttribute to look up the Session for a given HttpServletRequest , perhaps it works to use a WeakHashMap keyed by HttpServletRequest ?
|
Nope:
vs.
Still looking into options. |
I think I found a better approach. |
Closing in favor of #7412. |
This is causing a memory leak, as sessions pile up there and the GC does not collect them.
See JENKINS-70103 for more information.
I'll file a follow up PR in remoting to slow down connection re-try at agent side. There is no point on trying hundreds of times per second.
Testing done
AFAICT the current test setup is not ready to test an agent running on Java 8 trying to connect to Jenkins on Java 11, so I did some manual tests:
jenkins.websocket.Jetty10Provider.sessions
is clear.Proposed changelog entries
Proposed upgrade guidelines
N/A
Submitter checklist
@Restricted
or have@since TODO
Javadocs, as appropriate.@Deprecated(since = "TODO")
or@Deprecated(forRemoval = true, since = "TODO")
, if applicable.eval
to ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@jenkinsci/core-pr-reviewers
Maintainer checklist
Before the changes are marked as
ready-for-merge
:upgrade-guide-needed
label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidate
to be considered (see query).