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

[Websocket] Fix ClassCastException when user create MultiTopicReader. #14316

Merged
merged 4 commits into from
Feb 17, 2022
Merged

[Websocket] Fix ClassCastException when user create MultiTopicReader. #14316

merged 4 commits into from
Feb 17, 2022

Conversation

mattisonchao
Copy link
Member

@mattisonchao mattisonchao commented Feb 16, 2022

Motivation

Users who use the WebSocket API to create a new reader with the partitioned topic will get ClassCastException.

15:44:23.004 [pulsar-websocket-web-1-5] WARN  org.apache.pulsar.websocket.ReaderHandler - [xx.xx.x.xx:35389] Failed in creating reader  on topic persistent://xxxxxx/aaaaaaa/zzzzzz
java.lang.ClassCastException: class org.apache.pulsar.client.impl.MultiTopicsReaderImpl cannot be cast to class org.apache.pulsar.client.impl.ReaderImpl (org.apache.pulsar.client.impl.MultiTopicsReaderImpl and org.apache.pulsar.client.impl.ReaderImpl are in unnamed module of loader 'app')
	at org.apache.pulsar.websocket.ReaderHandler.<init>(ReaderHandler.java:107) ~[io.streamnative-pulsar-websocket-2.8.2.2.jar:2.8.2.2]
	at org.apache.pulsar.websocket.WebSocketReaderServlet.lambda$configure$0(WebSocketReaderServlet.java:44) ~[io.streamnative-pulsar-websocket-2.8.2.2.jar:2.8.2.2]
	at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:230) ~[org.eclipse.jetty.websocket-websocket-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:215) ~[org.eclipse.jetty.websocket-websocket-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.websocket.servlet.WebSocketServlet.service(WebSocketServlet.java:160) ~[org.eclipse.jetty.websocket-websocket-servlet-9.4.43.v20210629.jar:9.4.43.v20210629]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-javax.servlet-api-3.1.0.jar:3.1.0]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[org.eclipse.jetty-jetty-servlet-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550) ~[org.eclipse.jetty-jetty-servlet-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) ~[org.eclipse.jetty-jetty-servlet-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388) ~[org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633) [org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380) [org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [org.eclipse.jetty-jetty-server-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:555) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:410) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:164) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [org.eclipse.jetty-jetty-io-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [org.eclipse.jetty-jetty-util-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [org.eclipse.jetty-jetty-util-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [org.eclipse.jetty-jetty-util-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [org.eclipse.jetty-jetty-util-9.4.43.v20210629.jar:9.4.43.v20210629]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:386) [org.eclipse.jetty-jetty-util-9.4.43.v20210629.jar:9.4.43.v20210629]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [io.netty-netty-common-4.1.72.Final.jar:4.1.72.Final]
	at java.lang.Thread.run(Thread.java:829) [?:?]

Modifications

  • Convert it based on type judgment.

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

Check the box below or label this PR directly (if you have committer privilege).

Need to update docs?

  • no-need-doc

@mattisonchao mattisonchao changed the title Fix CastException when user create MultiTopicReader by websocket. Fix ClassCastException when user create MultiTopicReader by WebSocket. Feb 16, 2022
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Feb 16, 2022
@mattisonchao mattisonchao changed the title Fix ClassCastException when user create MultiTopicReader by WebSocket. [Websocket] Fix ClassCastException when user create MultiTopicReader. Feb 16, 2022
Copy link
Contributor

@Technoboy- Technoboy- left a comment

Choose a reason for hiding this comment

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

LGTM

@mattisonchao
Copy link
Member Author

Maybe we need to cherry-pick this PR to branch 2.8, branch 2.9?

@codelipenghui codelipenghui added this to the 2.11.0 milestone Feb 17, 2022
@codelipenghui codelipenghui merged commit 7a7cf54 into apache:master Feb 17, 2022
michaeljmarshall pushed a commit that referenced this pull request Feb 24, 2022
@michaeljmarshall michaeljmarshall added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Feb 24, 2022
gaoran10 pushed a commit that referenced this pull request Mar 1, 2022
@gaoran10 gaoran10 added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Mar 2, 2022
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
michaeljmarshall pushed a commit that referenced this pull request May 5, 2022
michaeljmarshall pushed a commit to datastax/pulsar that referenced this pull request May 5, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request May 9, 2022
…eader``. (apache#14316)

(cherry picked from commit 7a7cf54)
(cherry picked from commit 91b9f42)
michaeljmarshall added a commit that referenced this pull request May 11, 2022
### Motivation

This fixes an issue similar to the one solved in #14316. When the `reader` is a `MultiTopicReader`, the `getConsumer()` method currently throws a `ClassCastException`.

### Modifications

* Update `MultiTopicReader#getConsumer` so that it safely casts the `reader`.
* Update the `ReaderHandler` constructor to use the `getConsumer` method.

### Verifying this change

I expanded existing tests to cover the scenario that would have previously failed.

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

No, this is not a breaking change.
michaeljmarshall added a commit that referenced this pull request May 11, 2022
### Motivation

This fixes an issue similar to the one solved in #14316. When the `reader` is a `MultiTopicReader`, the `getConsumer()` method currently throws a `ClassCastException`.

### Modifications

* Update `MultiTopicReader#getConsumer` so that it safely casts the `reader`.
* Update the `ReaderHandler` constructor to use the `getConsumer` method.

### Verifying this change

I expanded existing tests to cover the scenario that would have previously failed.

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

No, this is not a breaking change.

(cherry picked from commit dd6d372)
michaeljmarshall added a commit to michaeljmarshall/pulsar that referenced this pull request May 11, 2022
…he#15534)

### Motivation

This fixes an issue similar to the one solved in apache#14316. When the `reader` is a `MultiTopicReader`, the `getConsumer()` method currently throws a `ClassCastException`.

### Modifications

* Update `MultiTopicReader#getConsumer` so that it safely casts the `reader`.
* Update the `ReaderHandler` constructor to use the `getConsumer` method.

### Verifying this change

I expanded existing tests to cover the scenario that would have previously failed.

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

No, this is not a breaking change.

(cherry picked from commit dd6d372)
michaeljmarshall added a commit that referenced this pull request May 11, 2022
### Motivation

This fixes an issue similar to the one solved in #14316. When the `reader` is a `MultiTopicReader`, the `getConsumer()` method currently throws a `ClassCastException`.

### Modifications

* Update `MultiTopicReader#getConsumer` so that it safely casts the `reader`.
* Update the `ReaderHandler` constructor to use the `getConsumer` method.

### Verifying this change

I expanded existing tests to cover the scenario that would have previously failed.

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

No, this is not a breaking change.

(cherry picked from commit dd6d372)
michaeljmarshall added a commit to datastax/pulsar that referenced this pull request May 11, 2022
…he#15534)

### Motivation

This fixes an issue similar to the one solved in apache#14316. When the `reader` is a `MultiTopicReader`, the `getConsumer()` method currently throws a `ClassCastException`.

### Modifications

* Update `MultiTopicReader#getConsumer` so that it safely casts the `reader`.
* Update the `ReaderHandler` constructor to use the `getConsumer` method.

### Verifying this change

I expanded existing tests to cover the scenario that would have previously failed.

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

No, this is not a breaking change.

(cherry picked from commit dd6d372)
michaeljmarshall added a commit to datastax/pulsar that referenced this pull request May 11, 2022
…he#15534)

### Motivation

This fixes an issue similar to the one solved in apache#14316. When the `reader` is a `MultiTopicReader`, the `getConsumer()` method currently throws a `ClassCastException`.

### Modifications

* Update `MultiTopicReader#getConsumer` so that it safely casts the `reader`.
* Update the `ReaderHandler` constructor to use the `getConsumer` method.

### Verifying this change

I expanded existing tests to cover the scenario that would have previously failed.

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

No, this is not a breaking change.

(cherry picked from commit dd6d372)
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.

6 participants