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][ws] Check the validity of config before start websocket service #22231

Merged
merged 2 commits into from
Mar 14, 2024

Conversation

Shawyeok
Copy link
Contributor

@Shawyeok Shawyeok commented Mar 9, 2024

Motivation

Now if user start a websocket service without clusterName, service will be started as normal, but it'll get NPE in the after produce request.

The websocket service will log this line below:

2024-03-09T16:53:22,468 - WARN  - [pulsar-websocket-web-1-1:ProducerHandler@129] - \
  [[0:0:0:0:0:0:0:1]:49221] Failed in creating producer on topic persistent://public/non-exist/my-topic: java.lang.NullPointerException
The NPE stacktrace (which is missing in log)
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.websocket.WebSocketService.retrieveClusterData(WebSocketService.java:261) ~[classes/:?]
	at org.apache.pulsar.websocket.WebSocketService.getPulsarClient(WebSocketService.java:185) ~[classes/:?]
	at org.apache.pulsar.websocket.ProducerHandler.(ProducerHandler.java:111) ~[classes/:?]
	at org.apache.pulsar.websocket.WebSocketProducerServlet.lambda$configure$0(WebSocketProducerServlet.java:43) ~[classes/:?]
	at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:275) ~[websocket-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:260) ~[websocket-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:160) ~[websocket-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[jetty-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1656) ~[jetty-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.servlets.QoSFilter.doFilter(QoSFilter.java:202) ~[jetty-servlets-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193) ~[jetty-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1626) ~[jetty-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:552) ~[jetty-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505) ~[jetty-servlet-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) ~[jetty-server-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) ~[jetty-io-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[jetty-io-9.4.54.v20240208.jar:9.4.54.v20240208]
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) ~[jetty-io-9.4.54.v20240208.jar:9.4.54.v20240208]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.105.Final.jar:4.1.105.Final]
	at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:208) ~[?:?]
	at com.google.common.base.Joiner.toString(Joiner.java:484) ~[guava-32.1.2-jre.jar:?]
	at com.google.common.base.Joiner.appendTo(Joiner.java:119) ~[guava-32.1.2-jre.jar:?]
	at com.google.common.base.Joiner.appendTo(Joiner.java:168) ~[guava-32.1.2-jre.jar:?]
	at com.google.common.base.Joiner.appendTo(Joiner.java:154) ~[guava-32.1.2-jre.jar:?]
	at com.google.common.base.Joiner.appendTo(Joiner.java:182) ~[guava-32.1.2-jre.jar:?]
	at org.apache.pulsar.broker.resources.BaseResources.joinPath(BaseResources.java:239) ~[classes/:?]
	at org.apache.pulsar.broker.resources.ClusterResources.getCluster(ClusterResources.java:67) ~[classes/:?]
	at org.apache.pulsar.websocket.WebSocketService.retrieveClusterData(WebSocketService.java:258) ~[classes/:?]
	... 38 more

Modifications

  • Check the validity of websocket config before it start
  • Log stacktrace if we get internal error in ProducerHandler

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: Shawyeok#12

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 9, 2024
@Technoboy- Technoboy- added this to the 3.3.0 milestone Mar 12, 2024
@Shawyeok
Copy link
Contributor Author

/pulsarbot rerun-failure-checks

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.64%. Comparing base (bbc6224) to head (828eb90).
Report is 48 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #22231      +/-   ##
============================================
+ Coverage     73.57%   73.64%   +0.07%     
+ Complexity    32624    32266     -358     
============================================
  Files          1877     1879       +2     
  Lines        139502   139801     +299     
  Branches      15299    15340      +41     
============================================
+ Hits         102638   102960     +322     
+ Misses        28908    28864      -44     
- Partials       7956     7977      +21     
Flag Coverage Δ
inttests 26.59% <38.46%> (+2.01%) ⬆️
systests 24.30% <0.00%> (-0.02%) ⬇️
unittests 72.91% <61.53%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...a/org/apache/pulsar/websocket/ProducerHandler.java 63.15% <100.00%> (+0.70%) ⬆️
...sar/websocket/service/WebSocketServiceStarter.java 76.00% <100.00%> (+1.53%) ⬆️

... and 75 files with indirect coverage changes

@nodece nodece merged commit 9ace957 into apache:master Mar 14, 2024
50 checks passed
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 15, 2024
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 17, 2024
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 17, 2024
mukesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 19, 2024
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants