mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-07-27 17:33:15 +00:00
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:
parent
dedd7cb1d0
commit
875d7d8e6e
@ -1073,6 +1073,11 @@ proc finish*(request: HttpClientRequestRef): Future[HttpClientResponseRef] {.
|
|||||||
## Finish sending request and receive response.
|
## Finish sending request and receive response.
|
||||||
doAssert(not(isNil(request.connection)),
|
doAssert(not(isNil(request.connection)),
|
||||||
"Request missing connection instance")
|
"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,
|
doAssert(request.state == HttpReqRespState.Open,
|
||||||
"Request's state is " & $request.state)
|
"Request's state is " & $request.state)
|
||||||
doAssert(request.connection.state ==
|
doAssert(request.connection.state ==
|
||||||
|
|||||||
@ -53,6 +53,7 @@ type
|
|||||||
HttpProtocolError* = object of HttpError
|
HttpProtocolError* = object of HttpError
|
||||||
HttpRedirectError* = object of HttpError
|
HttpRedirectError* = object of HttpError
|
||||||
HttpAddressError* = object of HttpError
|
HttpAddressError* = object of HttpError
|
||||||
|
HttpUseClosedError* = object of HttpError
|
||||||
|
|
||||||
KeyValueTuple* = tuple
|
KeyValueTuple* = tuple
|
||||||
key: string
|
key: string
|
||||||
@ -111,6 +112,9 @@ template newHttpReadError*(message: string): ref HttpReadError =
|
|||||||
template newHttpWriteError*(message: string): ref HttpWriteError =
|
template newHttpWriteError*(message: string): ref HttpWriteError =
|
||||||
newException(HttpWriteError, message)
|
newException(HttpWriteError, message)
|
||||||
|
|
||||||
|
template newHttpUseClosedError*(): ref HttpUseClosedError =
|
||||||
|
newException(HttpUseClosedError, "Connection was already closed")
|
||||||
|
|
||||||
iterator queryParams*(query: string,
|
iterator queryParams*(query: string,
|
||||||
flags: set[QueryParamsFlag] = {}): KeyValueTuple {.
|
flags: set[QueryParamsFlag] = {}): KeyValueTuple {.
|
||||||
raises: [Defect].} =
|
raises: [Defect].} =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user