Skip to content

[Fix][Client] Fixed cnx channel Inactive causing the request fail to time out and fail to return - #17051

Merged
codelipenghui merged 5 commits into
apache:masterfrom
liangyepianzhou:xiangying/txn/cnx_pendingrequest
Aug 18, 2022
Merged

codelipenghui merged 5 commits into
apache:masterfrom
liangyepianzhou:xiangying/txn/cnx_pendingrequest

Conversation

@liangyepianzhou

@liangyepianzhou liangyepianzhou commented Aug 10, 2022 •

Copy link
Copy Markdown
Contributor

Motivation

There may be a concurrency problem between sendRequestAndHandleTimeout and channelInactive, which may cause the future not to be completed and cause the thread to get stuck.

  1. channelInactive:
    1.1 complete all futures in pendingRequests
    1.2 and then clear the pendingRequests.
  2. sendRequestAndHandleTimeout
    2.1 put a request into pending
    2.2 write the requests into the channel, if ailed, the listener will remove the request from pendingRequests. And complete exceptionally.

If the execution order is 1.1 -> 2.1 -> 1.2 -> 2.2, then the corresponding future cannot be retrieved at 2.2. 2.1 The future put in will never be completed.

Modification

Delete pendingRequests.clear(), but all use remove to clear the request.

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

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

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

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

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)
  • The rest endpoints: (yes / no)
  • The admin cli options: (yes / no)
  • Anything that affects deployment: (yes / no / don't know)

Documentation

Check the box below or label this PR directly.

Need to update docs?

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

…time out and fail to return

### Motivation
There may be a concurrency problem between sendRequestAndHandleTimeout and channelInactive, which may cause the future to not be completed and cause the thread to get stuck.
1. channelInactive:
   1.1 complete all futures in pendingRequests
   1.2 and then clear the pendingRequests.
2. sendRequestAndHandleTimeout
   2.1 put request into pending
   2.2 write the requests into channel, if ailed, the listener will remove the request from pendingRequests. And complete exceptionally.

If the execution order is 1.1 -> 2.1 -> 1.2 -> 2.2, then the corresponding future cannot be retrieved at 2.2. 2.1 The future put in will never be completed.
### Modification
Delete pendingRequests.clear(), but all use remove to clear the request.

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, please also help check if there are other cases also need the same fix, such as lookup, tc handler, etc.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

overall LGTM

but I have left a question
I am afraid we will see "ConcurrentModificationException"
can you please double check ?

@liangyepianzhou

Copy link
Copy Markdown
Contributor Author

LGTM, please also help check if there are other cases also need the same fix, such as lookup, tc handler, etc.

TC handler has a check for the handler state. Nowhere else found anything like pendingRequests.clear()

@codelipenghui
codelipenghui merged commit 7913fe5 into apache:master Aug 18, 2022
congbobo184 pushed a commit that referenced this pull request Aug 18, 2022
…time out and fail to return (#17051)

(cherry picked from commit 7913fe5)
congbobo184 pushed a commit that referenced this pull request Aug 18, 2022
…time out and fail to return (#17051)

(cherry picked from commit 7913fe5)
congbobo184 pushed a commit that referenced this pull request Aug 18, 2022
…time out and fail to return (#17051)

(cherry picked from commit 7913fe5)
@Technoboy- Technoboy- removed this from the 2.12.0 milestone Aug 18, 2022
@Technoboy- Technoboy- added this to the 2.11.0 milestone Aug 18, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Aug 22, 2022
…time out and fail to return (apache#17051)

(cherry picked from commit 7913fe5)
(cherry picked from commit 8b792c4)
@syhily

syhily commented Sep 9, 2022

Copy link
Copy Markdown

When will this fix get released?

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

Labels

area/client cherry-picked/branch-2.9 Archived: 2.9 is end of life cherry-picked/branch-2.10 cherry-picked/branch-2.11 doc-not-needed Your PR changes do not impact docs release/2.9.4 release/2.10.2 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants