Skip to content

RestClient: cancelling Uni subscription doesn't cancel http request, if it was in queue (all connections was busy) #48620

@g0rba4ev

Description

@g0rba4ev

Describe the bug

My case:

  1. I subscribe on several Unis which are using RestClient async calls, but all available connections for RestClient are busy
  2. Then I cancel subscriptions of this Unis
  3. When connections for RestClient become available, RestClient calls executed from Uni that I just cancelled.

This is unexpected and not obvious behavior


I've found an Issue #41971 that was fixed, but as I see it only cancels requests that are already executing. In my case some requests (even after Uni cancelling) end up in some queue (?), and then are executed.

Prepared simple project for issue reproducing
https://github.com/g0rba4ev/quarkus_requests_not_cancelled
Check and run FooTest.java
There is a log in attachments (some lines with Responses are omitted for clarity)
log_resp_delay_10.log

I discovered that only some requests of cancelled Unis are executed, and this number of requests vary depending on delay of MockServer response.

You can change the variable delaySec at line 26 of file WiremockPlus.java and run the test to make sure of this dependency. (e.g. try 5 sec or 20 sec).

Maybe some queue of connection waiters is cleaned by some event or whatever, but I didn't manage to get any correlation between time interval from moment of cancelling Uni to moment of releasing occupied connections and number of executed requests from Uni that were cancelled.
The only correlation I've found is described above (delay of serves response)


I guess these "not cancelled" requests are stuck somewhere in SipmleConnectionPool, but I didn't dig deeper and I'm not sure.
Check io.vertx.core.net.impl.pool.SimpleConnectionPool.Acquire#execute method, lines under comment

// 4. Fall in waiters list

Feel free to ask any question.
Sincerely yours, g00d_men.

Expected behavior

All requests from cancelled Unis (requests that were in some queue) are not going to be sent

Actual behavior

Some of requests from cancelled Unis ( (requests that were in some queue) are sent

How to Reproduce?

  1. Download project https://github.com/g0rba4ev/quarkus_requests_not_cancelled
  2. Run FooTest.java

Or:

  1. Limit the number of connections for RestClient
  2. Occupy all these connections
  3. Create some Unis triggering RestClient async calls (more than a number of allowed parallel connections) and subscribe on them
  4. Cancel subscriptions on Unis
  5. Observe (e.g. by logs) that requests are still sent despite the fact that Unis were cancelled.

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions