Skip to content

[JENKINS-68933] Better WebSocket testing, removal of reflection - #6780

Merged
basil merged 16 commits into
jenkinsci:masterfrom
jglick:ws-JENKINS-68933
Jul 7, 2022
Merged

[JENKINS-68933] Better WebSocket testing, removal of reflection#6780
basil merged 16 commits into
jenkinsci:masterfrom
jglick:ws-JENKINS-68933

Conversation

@jglick

@jglick jglick commented Jul 5, 2022

Copy link
Copy Markdown
Member

See JENKINS-68933 and #6694 (comment). Amending #4369.

Proposed changelog entries

  • N/A (internal changes only)

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@jglick
jglick requested review from basil, daniel-beck and timja July 5, 2022 13:23
@jglick

jglick commented Jul 5, 2022

Copy link
Copy Markdown
Member Author

Looking over jetty/jetty.project#6623 & jetty/jetty.project#3544 & jetty/jetty.project#5874. Does not look like this will be straightforward—the APIs have changed substantially, and until jenkins-test-harness is also on Jetty 10, (non-Real) JenkinsRule-based tests will still require the old APIs, so the reflection will need to support both.

@timja

timja commented Jul 5, 2022

Copy link
Copy Markdown
Member

and until jenkins-test-harness is also on Jetty 10

could we just move it across? and maintain a backport line for fixes that are substantial enough?

@jglick

jglick commented Jul 5, 2022

Copy link
Copy Markdown
Member Author

Perhaps. First I want to try to get it to work on 10, and then I can look into making it still work on 9.

@jglick jglick mentioned this pull request Jul 5, 2022
12 tasks
@jglick
jglick force-pushed the ws-JENKINS-68933 branch from fc7b2fd to 8a14f9d Compare July 5, 2022 18:47
@jglick

jglick commented Jul 5, 2022

Copy link
Copy Markdown
Member Author

Rebased the test on top of the parent of #6694, where it passed.

@jglick

jglick commented Jul 5, 2022

Copy link
Copy Markdown
Member Author

Tests appear to fail here because the build is running PR-merge strategy. @timja @dduportal I thought we had decided to switch builds of this repo to use PR-head strategy? Maybe it was only bom?

@timja

timja commented Jul 5, 2022

Copy link
Copy Markdown
Member

Tests appear to fail here because the build is running PR-merge strategy. @timja @dduportal I thought we had decided to switch builds of this repo to use PR-head strategy? Maybe it was only bom?

only bom was switched

@jglick jglick changed the title [JENKINS-68933] WebSocket broken after Jetty upgrade [JENKINS-68933] Better WebSocket testing, removal of reflection Jul 5, 2022
@jglick
jglick marked this pull request as ready for review July 5, 2022 23:09
@jglick

jglick commented Jul 5, 2022

Copy link
Copy Markdown
Member Author

Split off #6785 to attempt (so far without success) to use this framework to support Jetty 10.

@basil basil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks Jesse, I had started working on a similar PR earlier today but you obviously got it done a lot faster. In the interest of saving time I took the liberty of pushing a few commits to your branch to fix static analysis issues. I also left a comment in #6785 (comment) explaining how to get this to work with Jetty 10.

@basil

basil commented Jul 6, 2022

Copy link
Copy Markdown
Member

Well now there's a a javadoc: error - No public or protected classes found to document but once that is resolved I think this is good to go.

Comment thread pom.xml
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Medium</spotbugs.threshold>
<spotbugs.excludeFilterFile>${project.basedir}/../src/spotbugs/spotbugs-excludes.xml</spotbugs.excludeFilterFile>
<spotbugs.excludeFilterFile>${maven.multiModuleProjectDirectory}/src/spotbugs/spotbugs-excludes.xml</spotbugs.excludeFilterFile>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TIL

@jglick

jglick commented Jul 6, 2022

Copy link
Copy Markdown
Member Author

In the interest of saving time

Well, there is no rush on this one since it does not fix anything for users, it is just making it easier to work on this code.

I took the liberty of pushing a few commits to your branch to fix static analysis issues.

Thanks! I will check the Javadoc issue.

Comment thread websocket/spi/pom.xml
Comment on lines +63 to +65
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that this should probably also be done in the cli and war modules.

};
}

private static Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note the Object in the signature. Javadoc is super helpful

a websocket object to use

It is more or less through trial and error that I concluded (in #4369) that a WebSocketListener is expected; “normal usage” apparently means adding annotations to POJOs and just remembering what method signatures to use. I think this misconceived style is inherited from the javax.websocket API. (Which tries to make you declare WS-aware endpoints with more annotations, and fails to provide a simple Java API call to upgrade a connection, forcing us to rely on Jetty-specific APIs.)

Otherwise closing connections sometimes produces stack traces

```
WARNING	j.websocket.WebSocketSession#error: unhandled WebSocket service error
java.nio.channels.ClosedChannelException
	at org.eclipse.jetty.websocket.core.internal.WebSocketSessionState.onEof(WebSocketSessionState.java:169)
	at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.onEof(WebSocketCoreSession.java:253)
	at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.fillAndParse(WebSocketConnection.java:482)
	at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.onFillable(WebSocketConnection.java:340)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
	at …
```

or

```
WARNING	j.agents.WebSocketAgents$Session#error
java.nio.channels.ClosedChannelException
	at org.eclipse.jetty.websocket.core.internal.WebSocketSessionState.onEof(WebSocketSessionState.java:169)
	at org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession.onEof(WebSocketCoreSession.java:253)
	at …
```

though I am not sure if that is actually new behavior.
@basil

basil commented Jul 6, 2022

Copy link
Copy Markdown
Member

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process. Thanks!

@basil basil added ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog labels Jul 6, 2022
Comment thread bom/pom.xml
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that this will cause that library to be managed for plugin POMs (like credentials or artifact-manager-s3) for the first time. Seems like a good thing; I am not sure why it was not already in the core BOM. But if this is a problem for any reason, it could trivially be reverted, and the version fixed in the new module.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I don't see a problem with including it in the core BOM. This PR does also start shipping WEB-INF/lib/metainf-services-1.9.jar, which seems harmless, but I'm not entirely sure it's necessary either, since it seems to be more of a compile-time thing. No request for change or action item here, just noting the additional JAR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW there is an exclusion for this library elsewhere in the build: https://github.com/jenkinsci/jenkins/blob/644a261e78e9d80e2442787c8418cbdf283ac7e1/war/pom.xml#L92-L96=

Comment thread websocket/spi/pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Deliberately not using BOM version here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I saw that and I agree with using 3.1.0 because that is the lowest common denominator for Jetty 9 and Jetty 10. But the downside is this is adding the JAR to WEB-INF/lib/javax.servlet-api-3.1.0.jar in the WAR, which I think is undesirable because it is not actually used at runtime; rather, Winstone's copy is used. So to fix this I think we should exclude it when we pull in websocket-spi in core/pom.xml, which already has a provided dependency on servlet-api that is aligned with Jetty's.

@jglick
jglick marked this pull request as draft July 6, 2022 17:24
@jglick
jglick marked this pull request as ready for review July 6, 2022 17:30
basil pushed a commit to jglick/jenkins that referenced this pull request Jul 6, 2022

@olamy olamy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh yes Jetty 10 API for websocket has changed a lot (it's supposed to be more easy to use but still a big change...)
good work here! (Hopefully we will not have to keep this jetty9 too long?)

private static final String ATTR_LISTENER = Jetty9Provider.class.getName() + ".listener";

// TODO does not seem possible to use HttpServletRequest.get/setAttribute for this
private static final Map<Listener, Session> sessions = new WeakHashMap<>();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

regression: #7076

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants