Tentative fix for the HTTP client connection state assertion failures (#272)

* Tentative fix for the HTTP client connection state assertion failures

I've traced the problem to a HTTP connection being closed while there
are outstanding requests that still go through the motions (the crash
occurs when a requests reaches its `finish` processing step, but it
was already put in a Closed state by the connection that owns it).

* Use distinct error exception instead of cancellation error.

Co-authored-by: cheatfate <eugene.kabanov@status.im>
This commit is contained in:
zah 2022-05-14 11:08:13 +03:00 committed by GitHub
parent dedd7cb1d0
commit 875d7d8e6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -1073,6 +1073,11 @@ proc finish*(request: HttpClientRequestRef): Future[HttpClientResponseRef] {.
## Finish sending request and receive response.
doAssert(not(isNil(request.connection)),
"Request missing connection instance")
if request.connection.state in {HttpClientConnectionState.Closing,
HttpClientConnectionState.Closed}:
let e = newHttpUseClosedError()
request.setError(e)
raise e
doAssert(request.state == HttpReqRespState.Open,
"Request's state is " & $request.state)
doAssert(request.connection.state ==

View File

@ -53,6 +53,7 @@ type
HttpProtocolError* = object of HttpError
HttpRedirectError* = object of HttpError
HttpAddressError* = object of HttpError
HttpUseClosedError* = object of HttpError
KeyValueTuple* = tuple
key: string
@ -111,6 +112,9 @@ template newHttpReadError*(message: string): ref HttpReadError =
template newHttpWriteError*(message: string): ref HttpWriteError =
newException(HttpWriteError, message)
template newHttpUseClosedError*(): ref HttpUseClosedError =
newException(HttpUseClosedError, "Connection was already closed")
iterator queryParams*(query: string,
flags: set[QueryParamsFlag] = {}): KeyValueTuple {.
raises: [Defect].} =