* add missing calls to await
* add test run in v3 compatibility
* fix semantics for chronosHandleException so it does not override local raises/handleException annotations
* distinguish between explicit override and default setting; fix test
* re-enable wrongly disabled check
* make implementation simpler/clearer
* update docs
* reflow long line
* word swap
* Add automatic constructors for TCP and UDP transports.
* Add port number argument.
Add some documentation comments.
Fix tests.
* Make datagram test use request/response scheme.
* Add helper.
* Fix issue with non-zero port setups.
Add test.
* Fix tests to probe ports.
* Attempt to fix MacOS issue.
* Add Opt[IpAddress].
Make IPv4 mapping to IPv6 space automatic.
* Add tests.
* Add stream capabilities.
* Fix Linux issues.
* Make getTransportFlags() available for all OSes.
* Fix one more compilation issue.
* Workaround weird compiler bug.
* Fix forgotten typed version of constructor.
* Make single source for addresses calculation.
* Add one more check into tests.
* Fix flags not being set in transport constructor.
* Fix post-rebase issues with flags not being set.
* Address review comments.
In `stream.readLoop`, a finished `Future` was left in `transp.reader`
if there was an error in `resumeRead`. Set it to `nil` as well.
Co-authored-by: Jacek Sieka <jacek@status.im>
* Add more specific accept() exceptions raised.
Add some refactoring to HTTP server code.
* Refactor acceptLoop.
* Print GC statistics in every failing test.
* Try to disable failing tests.
* simplify `closeWait` implementations
* remove redundant cancellation callbacks
* use `noCancel` to avoid forgetting the right future flags
* add a few missing raises trackers
* enforce `OwnCancelSchedule` on manually created futures that don't raise `CancelledError`
* ensure cancellations don't reach internal futures
Because the callback types were used explicitly in some consumers of
chronos, the change of type introduces a backwards incompatibility
preventing a smooth transition to v4 for code that doesn't uses
`raises`.
This PR restores backwards compatibility at the expense of introducing a
new type with a potentially ugly name - that said, there is already
precedence for using numbered names to provide new error handling
strategy in chronos.
* Fixes.
* Make httpcommon no-raises.
* Make httpbodyrw no-raises.
* Make multipart no-raises.
* Make httpdebug no-raises.
* Make httpagent no-raises.
* Make httpclient no-raises.
* Make httpserver/shttpserver no-raises.
* fix prepend/remove when E is noraises
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
This avoids copies here and there throughout the pipeline - ie
`copyString` and friends can often be avoided when moving things into
and out of futures
Annoyingly, one has to sprinkle the codebase liberally with `sink` and
`move` for the pipeline to work well - sink stuff _generally_ works
better in orc/arc
Looking at nim 1.6/refc, sink + local variable + move generates the best
code:
msg directly:
```nim
T1_ = (*colonenv_).msg1; (*colonenv_).msg1 = copyStringRC1(msg);
```
local copy without move:
```nim
T60_ = (*colonenv_).localCopy1; (*colonenv_).localCopy1 =
copyStringRC1(msg);
```
local copy with move:
```nim
asgnRef((void**) (&(*colonenv_).localCopy1), msg);
```
Annoyingly, sink is also broken for refc+literals as it tries to
changes the refcount of the literal as part of the move (which shouldn't
be happening, but here we are), so we have to use a hack to find
literals and avoid moving them.
* Fix transports addresses functions should not return so many exceptions.
* Add raising `Defect` functions to AsyncQueue.
* Add raises/asyncraises into async streams.
* Remove `Safe` primitives.
Make AsyncStreamError to be ancestor of AsyncError.
Make AsyncStreamReader/Writer loops requirement to not raise any exceptions
* Remove `par` fields.
* Remove `par` fields from TLSStream.
* Attempt to lower memory usage.
With these fixes, `transports`/`asyncsync` correctly propagate and document their raises information - generally, most transport functions (send etc) raise `TransportError` and `CancelledError` - `closeWait` is special in that it generally doesn't fail.
This PR introduces the syntax `Future[void].Raises([types])` to create the `InternalRaisesFuture` type with the correct encoding for the types - this allows it to be used in user code while retaining the possibility to change the internal representation down the line.
* introduce raising constraints on stream callbacks - these constraints now give a warning when called with a callback that can raise exceptions (raising callbacks would crash
* fix fail and its tests, which wasn't always given a good generic match
* work around nim bugs related to macro expansion of generic types
* make sure transports raise only `TransportError`-derived exceptions (and `CancelledError`)
* Add callTick and stream cancellation tests.
* Fix stepsAsync() test.
* Cancellation changes.
* Update and add more cancellation tests.
* Fix Posix shutdown call to handle ENOTCONN error.
* With new changes to to cancellation its now possible.
* Refactor testsoon.nim to not produce artifacts after tests are finished.
* Debugging MacOS issue.
* Adjust flaky test times.
* Fix issue.
* Add test for issue #334 which was also addressed in this PR.
Avoid `break` in problematic test.
* Add noCancelWait() call which prohibits cancellation.
Fix closeWait() calls to use noCancelWait() predicate.
Adding sleep to flaky MacOS test.
* Remove all debugging echoes.
* Fix cancelAndWait() which now could perform multiple attempts to cancel target Future (mustCancel behavior).
* Fix issues revealed by switch to different cancelAndWait().
* Address review comments.
* Fix testutils compilation warning.
* Rename callTick() to internalCallTick().
* Add some documentation comments.
* Disable flaky ratelimit test.
* Rename noCancelWait() to noCancel().
Address review comments.
* Refactor chronos trackers to be more simple.
* Refactor trackers.
Add HTTP server trackers.
Refactor HTTP main processing loop.
* Compatibility fixes.
Add checkLeaks().
* Fix posix test issue.
* Add httpdebug module which introduces HTTP connection dumping helpers.
Add tests for it.
* Recover and deprecate old version of Trackers.
* Make public iterators to iterate over all tracker counters available.
Fix asynctests to use public iterators instead private one.
* Initial Windows asyncproc part.
Deprecate usage of net/nativesockets in handles, asyncloop.
Introduce primitives with inheritable flag.
* Some posix fixes.
* More duplicate fixes.
* Fix AsyncProcessOption.EchoCommand option.
Remove isMainModule code.
Fix execCommand to use AsyncProcessOption.EvalCommand.
* Initial asyncproc tests commit.
* Some Posix fixes.
* Fix Posix crash.
* Add testsuite.
Fix osnet.nim to use proper declarations.
Fix timer.nim to use proper declarations.
Add Windows environment handling procedures.
Fix createAsyncPipe.
Add leaks tracking for AsyncProcessRef.
* Fix O_CLOEXEC constant value.
* Add file descriptors leak test.
* Remove commented code.
Refactor exceptions.
Fix compilation warnings.
* No exception ioselectors_kqueue initial commit.
* Some BSD fixes.
Linux refactoring of selectors.nim.
* Some fixes to move further.
* Last Linux fixes.
* Fixes for asyncloop to use 2nd version of selectors api.
* Add osutils.nim.
* Some fixes.
* Hardening resumeRead(), resumeWrite() and consumers.
Add ESRCH handling.
Introduce no-exception fromPipe2.
* Make Windows part exception-free and fix zombie race issue.
* createStreamServer() fixes.
* Upgrade asyncproc to use non-exception primitives.
Fix ioselectors_kqueue to use closeFd().
* Refactor accept() and acceptLoop() to be exception free.
* Deprecated some `result` usage.
Last fixes to make stream.nim exception free.
Use closeFd().
Refactor some loops to use handleEintr().
* Fix connect() forgot to unregister socket on error.
* All createAsyncSocket() sockets should be closed with unregisterAndCloseFd().
* Attempt to fix posix bug with incomplete output.
* Change number of runs in big test.
* Refactoring pipes creation. Attempt to fix "write error: Resource temporarily unavailable".
* Fix waitForExit(duration) code.
Fix test exit code.
* Fix Windows missing SIGTERM.
* Fix mistype.
* Fix compilation error.
* Attempt to fix Nim 1.6 issue.
* Eliminate Nim's WideCString usage to avoid any problems in future.
* Deprecate posix usage in osnet.
* Eliminate unused imports.
* Some debugging statements for investigation.
* Remove all the debugging statements.
* Remove testhelpers in favor of unittest2/asynctests.
* Fix flaky test.
* Make test more resilient to timings.
* Add memory size dump to CI.
* Refactor some blocks to use valueOr.
Make waitForExit to use kill() instead of terminate().
* Remove memory dumps.
* Fix peekProcessExitCode() blocks issue.
* Fix Windows issue.
* Add some debugging echoes.
* Fix compilation error.
* Add some debugging echoes.
* Add more helpers.
* Fix compilation error.
* waitForExit() is primary suspect.
* Remove fast-path for waitForExit.
Remove loop for reading signal events.
* Remove all debugging echoes.
* Return one debugging echo.
* Fix futures tests.
* Add test for multiple processes waiting to attempt stress test.
* Refactor ioselectors_epoll for better signalfd and process monitoring.
Add more race condition fixes to waitForExit.
Fix some Nim 1.6 warnings.
* Fix after rebase issues and warnings.
* Fix style issues.
Fix different Nim versions issues.
Workaround `signalfd` style issues.
* Add one more Linux signals workaround.
Add one more multiple processes test.
* Windows fixes.
* Remove unixPlatform define.
Fix WSAECONNABORTED for devel.
* Temporarily disable rate limit tests.
Fix more devel issues.
* Deprecate `hasThreadSupport` for ioselectors_kqueue.
Fix verifySelectParams issue.
Add exit codes test for multiple processes.
Fix osnet PtrToCstringConv warning.
* ioselectors_kqueue refactoring.
* Initial commit.
* Fix 1.2-1.4 compilation issue.
* Fix unused warning for testCtrlC() test.
* Post-rebase fixes.
* Restore master files.
* More fixes.
* Remove duplicates.
* Fix style mistake.
* Add more flexible pragmas.
* Fix cast[pointer] issues on nim-devel.
* More cast[T] fixes.
* Fix compilation error.
* Add oserrno.nim
Further fixes for Windows and Linux.
* MacOS fixes.
* More Windows fixes and attempt to fix 1.2, 1.4 branches.
* Implicitly import/export oserrno.
* Replace oserrno with osdefs.
* Return back oserrno.
* epoll to oserrno.
* datagram/stream to oserrno.
* common to oserrno.
* test to oserrno.
* Add `localAddress` support to `stream.connect`
* fix windows
* TransportAddress() instead of AnyAddress
* tweak flags
* Better flags
* try to workaround nim 1.2 issue
* Handle ReusePort in createStreamServer and improve tests
* Rename ClientFlags to SocketFlags
---------
Co-authored-by: Diego <diego@status.im>
* Fix some warnings messages.
* More warning fixes.
* Address review comments.
Fix MacOS issues.
* More warning fixes.
* More Windows specific fixes.
* Fix macos and windows warnings.
* Fix warnings in timer.nim
Refactor to remove `result`.
Improve performance and behavior of timer to string procedure.
Add tests.
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.
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.
* 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.
* exception tracking
This PR adds minimal exception tracking to chronos, moving the goalpost
one step further.
In particular, it becomes invalid to raise exceptions from `callSoon`
callbacks: this is critical for writing correct error handling because
there's no reasonable way that a user of chronos can possibly _reason_
about exceptions coming out of there: the event loop will be in an
indeterminite state when the loop is executing an _random_ callback.
As expected, there are several issues in the error handling of chronos:
in particular, it will end up in an inconsistent internal state whenever
the selector loop operations fail, because the internal state update
functions are not written in an exception-safe way. This PR turns this
into a Defect, which probably is not the optimal way of handling things
- expect more work to be done here.
Some API have no way of reporting back errors to callers - for example,
when something fails in the accept loop, there's not much it can do, and
no way to report it back to the user of the API - this has been fixed
with the new accept flow - the old one should be deprecated.
Finally, there is information loss in the API: in composite operations
like `poll` and `waitFor` there's no way to differentiate internal
errors from user-level errors originating from callbacks.
* store `CatchableError` in future
* annotate proc's with correct raises information
* `selectors2` to avoid non-CatchableError IOSelectorsException
* `$` should never raise
* remove unnecessary gcsafe annotations
* fix exceptions leaking out of timer waits
* fix some imports
* functions must signal raising the union of all exceptions across all
platforms to enable cross-platform code
* switch to unittest2
* add `selectors2` which supercedes the std library version and fixes
several exception handling issues in there
* fixes
* docs, platform-independent eh specifiers for some functions
* add feature flag for strict exception mode
also bump version to 3.0.0 - _most_ existing code should be compatible
with this version of exception handling but some things might need
fixing - callbacks, existing raises specifications etc.
* fix AsyncCheck for non-void T