* move `Future[T]` into its own module along with some basic accessors
* mark all fields internal, exposing only read-only versions under the
old names
* introduce `init`/`completed`/etc as a way of creating a future (vs
newFuture)
* introduce `LocationKind` for `SrcLoc` access
* don't expose `FutureList` unless future tracking is enabled
* introduce `chronosStrictFutureAccess` which controls a number of
additional `Defect` being raised when accessing Future fields in the
wrong state - this will become true in a future version
In this version, `Future[T]` backwards compatibility code remains in
`asyncfutures2` meaning that if only `chronos/futures` is imported, only
"new" API is available.
This branch is a refinement / less invasive / minimal version of
https://github.com/status-im/nim-chronos/pull/373.
* 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.
* FutureState.Finished -> FutureState.Completed (to avoid name clash
with `proc finished` which means not-pending)
* deprecate `done` - to avoid additional confusion over completed vs
finished
* remove ad leftovers in stack trace formatting
* avoid some generic bloat
* avoid unnecessary allocations in `race`/`one`
* Initial commit.
* Some Linux fixes.
* Address review comments on Windows.
* Fix issues on Linux.
* Fix 1.2 issue and Windows warnings.
* Fix posix compilation issues.
* 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>
This PR moves all compile-time configuration to a single module,
simplifying documentation and access to these features.
Upcomfing features may be enabled either individually, or through a new
`chronosPreviewV4` catch-all designed to allow code to be prepared for
increased strictness in future chronos releases.
`-d:chronosDebug` may be used to enable the existing debugging helpers
together.
* Allow passing in trustAnchors to newTLSClientAsyncStream
* Store X509TrustAnchors in a memory-secure, but memory-friendly way
* Remove forgotten import
* Change some waitFor to await in tests; add comment about trustAnchors reuse
* Remove use of result in newTrustAnchorStore
Remove `result` usage.
Remove cast[T] usage.
Add more helpers for TransportAddress checks.
Add isGlobal() helper to check if TransportAddress is globally accessed IP address.
Add tests.
Add more tests for sub.
Add TransportAddress.toHex().
Allow `type = proc(...) {.async.}` for pre-declaring async callback
types - in this case, the macro applies the correct transformation to
the return type and adds the appropriate exception / gcsafe annotations
* Address #329.
* Refactor AsyncStreamReader/Writer `state` helper functions.
Fix some compilation warnings in `debugutils`.
Add multiple writes into test to check consistency.
* Fix Linux issue.
Fix warnings.
* 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.
Add IndexError crash test for Linux/MacOS.
Add Sentinel version of fix.
Add GetQueuedCompletionStatusEx() support for Windows, which allows to capture more then one event in single `poll()` call.
* AsyncEventQueue (AsyncEventBus replacement) initial commit.
* Add closeWait() and remove assertion test.
* Fix "possible" memory leak.
* Add limits to AsyncEventQueue[T].
Add tests for AsyncEventQueue[T] limits.
Rebase AsyncSync errors to be children of AsyncError.
* Adopt AsyncEventQueue to garbage collect events on emit() too.
Add test from review comment.
* Remove AsyncEventBus test suite.
* Remove unneeded [T] usage.
* Optimize memory usage in 1m test.
* Lower number of events in test from 1m to 100k.
* Deprecate AsyncEventBus.
Add some GC debugging for tests.
* Fix mistype.
* One more attempt to fix crash.
* Add some echo debugging.
* More echo debugging.
* More closer debug echoes.
* Attempt to workaround crash place.
* More debugging echoes in exception handlers.
* Convert suspected test into async procedure.
* Make multiple consumers test async.
* Remove GC debugging.
* Disable added tests.
* Disable AsyncEventQueue tests to confirm that this is an issue.
* Enable all the 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.
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.
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.
* 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.