Commit Graph

510 Commits

Author SHA1 Message Date
Eugene Kabanov 623681e212
Add nimRawSetjmp define to config.nims (#285)
* Add nimRawSetjmp define to config.nims

* Add config to tests too.
2022-06-14 01:02:33 +03:00
Eugene Kabanov b3548583fc
Fix last connection state check. (#278) 2022-05-27 23:03:32 +03:00
Eugene Kabanov 728ab7faa7
Fix one more place of assertion for high concurrency requests. (#277) 2022-05-27 20:28:39 +03:00
Tanguy c5894bae1b
AsyncEventBus: fix multiple listeners (#271)
Co-authored-by: dbrignoli <dbrignoli@audioscience.com>
2022-05-20 11:57:37 +02:00
Derek 呆 1233f8fb4b
fix tiny typo in comment (#274) 2022-05-19 17:37:51 +02:00
zah 875d7d8e6e
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>
2022-05-14 11:08:13 +03:00
Etan Kissling dedd7cb1d0
Guarantee exclusive use of `HttpClientConnection`. (#273)
When calling the HTTP `send` / `open` functions, `acquireConnection` is
called to obtain a connection in state `Ready`. In the next code block,
the connection state is advanced to `RequestHeadersSending`. However,
returning from chronos `async` procs yields control, similar to `await`.
This means that a connection may be added to the pool in `Ready` state,
and then a different `acquireConnection` call may obtain a second ref.
Introducing a new `Acquired` state ensures consistency in this case.

No tests added due to this being scheduler dependent; ran manual tests
by adding a `doAssert item.state != HttpClientConnectionState.Acquired`
between `if not(isNil(conn)):` and `return conn`. Eventually, the assert
got hit after several hours of repeated tests, confirming the edge case
to be solved by applying this fix.

Not sure if it is by design that returning from an `async` proc yields.
Even if it's not, this should solve current HTTP issues in nimbus-eth2.
2022-05-13 02:54:34 +03:00
Tanguy ae19d5b6f0
Handle multiple childs for opensymchoice (#266)
And more tests. Follow up of #261
2022-05-05 11:05:04 +02:00
zah 5a906ad56c
nimble setup (#269) 2022-04-17 11:41:14 +02:00
Jacek Sieka bb4c3298f5
fix crash after reading from fd > 1024 (#267)
The socket selector holds a `seq` of per-descriptor data. When a reader
is registered, a pointer to a seq item is stored - when the `seq` grows,
this pointer becomes dangling and causes crashes like
https://github.com/status-im/nimbus-eth2/issues/3521.

It turns out that there already exist two mechanisms for passing user
data around - this PR simply removes one of them, saving on memory usage
and removing the need to store pointers to the `seq` data that become
dangling on resize.
2022-04-11 11:56:30 +02:00
cheatfate ae2a87778f
Fix missing connection flag. 2022-04-10 19:35:04 +03:00
Tanguy 64386b3112
Fix nimdoc for async procs (#260) 2022-04-05 12:16:00 +02:00
Tanguy 3621143c89
reenable auth test with other server 2022-03-30 17:09:43 +02:00
Tanguy 0bd9238409
Skip failing test to restore CI 2022-03-30 16:56:04 +02:00
Tanguy fc65ff8c5b
Cleanup return type open syms (#261) 2022-03-30 16:13:58 +03:00
Tanguy 8719723077
Fix TLS certificate allocation (#259)
* Fix TLS certificate allocation

* change style + comment
2022-01-28 13:46:15 +02:00
Thomas Jost b47b2a96ce
Fix documentation build (#258)
`nim doc --project --index:on chronos.nim` was failing with the following error:

    /path/to/nim-chronos/chronos/transports/common.nim(519, 21) Error: '*' expected

...which in turned caused errors in all files that import this one.

Now the entire docs can be built successfully, with only a few warnings.

Fixes #186.
2022-01-26 20:56:22 +01:00
Emil 1f37dac810 Refactor `preferredContentType` proc & add tests
Fix of the following bug:
In case of multiple accept headers with same preference
`preferredContentType` used to select the first match within content types
provided by the application. For example, if user specifies accept headers
`application/octet-stream, application/json` and application provides
`application/json, application/octet-stream`, `application/octet-stream`
will be returned, and that is a bug.

Now the procedure returns the most suitable match according
to the application preferences.
2022-01-25 16:05:36 +02:00
Eugene Kabanov 519ca463df
Fix transport.write() unable to send data through OS pipes. (#256)
* Fix transport.write() unable to send data through pipe.
Add test for pipes.

* Fix flaky test.

* Add workaround for Nim's issue #19425.
2022-01-20 18:38:41 +02:00
Ștefan Talpalaru 17fed89c99
style fixes (#253)
* style fixes

and disable the cron CI job
2022-01-04 23:14:30 +01:00
Tanguy d926415f42
Fixes for nimdoc (#252) 2022-01-04 18:00:17 +01:00
Jacek Sieka 0fc82049ac enable --styleCheck:usages 2021-12-27 17:33:25 +02:00
Tanguy 7dc58d42b6
Improve ram usage (#243)
Remove cyclic references of {.async.} Futures, allowing them to be picked up by the regular refc instead of Mark and Sweep
2021-12-10 11:19:14 +01:00
Zahary Karadjov 7ca85ddadc
Fix compilation errors with --styleCheck:usages --styleCheck:error 2021-12-08 16:58:24 +02:00
Tanguy cedc603b81
Remove future var (#247) 2021-12-08 12:30:12 +01:00
Jacek Sieka c25fa1f6cd
posix: fast path for write (#244)
When `write` is called on a `StreamTransport`, the current sequence of
operations is:

* copy data to queue
* register for "write" event notification
* return unfinished future to `write` caller
* wait for "write" notification (in `poll`)
* perform one `send`
* wait for notification again if there's more data to write
* complete the future

In this PR, we introduce a fast path for writing:

* If the queue is empty, try to send as much data as possible
  * If all data is sent, return completed future without `poll` round
  * If there's more data to send than can be sent in one go, add the
rest to queue
* If the queue is not empty, enqueue as above
* When notified that write is possible, keep writing until OS buffer is
full before waiting for event again

The fast path provides significant performance benefits when there are
many small writes, such as when sending gossip to many peers, by
avoiding the poll loop and data copy on each send.

Also fixes an issue where the socket would not be removed from the
writer set if there were pending writes on close.
2021-12-08 11:35:27 +01:00
Eugene Kabanov 7da1f5d4d2
Bump version to 3.0.9. (#249) 2021-12-03 15:32:58 +02:00
Eugene Kabanov 36e5f6fc89
Attempt to fix connection state. (#248)
* Attempt to fix connection state.

* Add actual values dump on asserts.

* Total rework of connection's states.
2021-12-03 13:11:39 +02:00
Eugene Kabanov 1c17d4c094
Fix connections management in http client. (#246)
* Proper connection lifetime handling mechanism.
HttpClientResponse do not close connection anymore.

* Add unique HTTP client connection identifier.
2021-12-01 12:23:39 +02:00
Andreas Rumpf 37c62af579
Added an explanation for the additional `gcsafe` pragmas (#241)
* prepare nim-chronos for Nim version 1.2

* enable --gc:orc testing

* ensure asyncmacro2 works with the upcoming 1.6

* added a remark
2021-11-22 14:48:59 +02:00
Ștefan Talpalaru ae95bc3d19
CI: test multiple Nim branches all the time (#240) 2021-11-20 14:29:09 +01:00
Ștefan Talpalaru 25ccbb0beb
version 3.0.8 2021-11-20 01:31:09 +01:00
Ștefan Talpalaru 4aaaa3379a
Nim-1.6 fixes (#239) 2021-11-20 01:30:23 +01:00
Eugene Kabanov f51158da65
Add NewConnectionAlways option to HttpClientFlags, which allows to ignore connection management in client. (#238)
Optimize server behavior when HeadersTimeout is set to Infinity.
2021-11-19 18:13:36 +02:00
Michael Bradley ad0029e3ee
add raises pragma to registerEvent in ioselectors_epoll (#237)
Include `IOSelectorsException` in addition to `Defect` in `raises: []`.
2021-11-19 17:47:58 +02:00
Ștefan Talpalaru b24ee653d3
version 3.0.7 2021-11-19 01:08:55 +01:00
Ștefan Talpalaru 56e007d165
comments for recent gcsafe pragmas 2021-11-19 01:07:46 +01:00
Andreas Rumpf cc22234dc6
Prepare chronos for Nim version 1.6 (#226) 2021-11-19 01:05:47 +01:00
Ștefan Talpalaru 0d46e0ff9b
CI: test multiple Nim branches in a daily cron job (#225) 2021-11-16 12:10:19 +01:00
Miran 3697426f85
properly move testing libbacktrace to a separate task (#236)
This is a continuation of #231.
2021-11-15 11:40:49 +01:00
Eugene Kabanov 0c7a0bd0a5
Handle accept() errors properly. (#234)
* Add more accept() call error handlers.
Fix issue when HTTP server silently stops accepting new connections.
Remove unneeded MacOS syscall to disable SIG_PIPE on socket, we already mask this signal in process.

* User `if` instead `case` because constants are actually variables.

* Fix mistypes.

* Do not use case for posix constants.

* Fix Linux compilation error.
2021-11-12 18:13:56 +02:00
Ștefan Talpalaru df980dd713
CI: separate libbacktrace test in its own task (#231) 2021-11-08 19:09:06 +02:00
Jacek Sieka 8ce9f54bb7
Document `-d:asyncBackend` (fixes #207) (#216) 2021-11-08 15:17:37 +01:00
cheatfate 661eae5732
Fix identifiers to be `uint` instead of `uint64`. 2021-10-21 17:46:06 +03:00
Eugene Kabanov 3bc0bc36f7
Change Future identifier type from `int` to `uint`. (#228)
* Change Future identifier type from `int` to `uint64`.

* Fix compilation error and tests.

* Add integer overflow test, to avoid confusion with next Nim versions, we expect that unsigned integers do not raise any exceptions if overflow happens.

* Switch from `uint64` to `uint` type.

* Add `uint` overflow tests.
2021-10-21 17:22:11 +03:00
cheatfate 2e57ddb455
Fix preferredContentType() function declaration to avoid confusion with `preferredContentType(varargs)`. 2021-10-21 14:01:46 +03:00
Eugene Kabanov 59b91bf0ca
Add more helpers to handle Accept header. (#224)
* Add API working with strings instead of `HttpRequestRef` object.

* Fix comment.
2021-09-28 01:41:29 +03:00
Eugene Kabanov d57aae27a0
Fix mingw64 distribution urls. (#223) 2021-09-27 18:40:42 +03:00
Eugene Kabanov 80102a3b6a
Eventbus implementation (#214)
* Initial commit.

* Move AsyncEventBus implementation to asyncsync.nim
Add subscriptAll(), waitAllEvents() primitives.
Add emitWait() primitive.
Add emitter source location implementation.
Add tests.
2021-09-15 16:55:15 +03:00
Eugene Kabanov bbbcb55493
Server-side events implementation. (#222)
Fix keep-alive issue.
Refactor some prepareXXX routines.
2021-09-14 20:32:58 +03:00