Skip to content
Discussion options

You must be logged in to vote

cancelToken.cancel() aborts the request and stops the Stream from emitting more data, but it doesn't necessarily force-close the underlying TCP socket — Dart's HttpClient (which dio's default IOHttpClientAdapter wraps) pools connections for reuse by default, so the socket can stay alive in the pool even after your request/subscription is done.

Two things that actually control this at the TCP level:

  1. dio.close(force: true) — this is the real "kill everything now" call. dio.close() without force waits for pending requests to finish before closing; force: true immediately aborts the underlying HttpClient and all its open sockets, not just the one request.
  2. Set persistentConnection: false in y…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by nurmohammed840
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants