691 Commits

Author SHA1 Message Date
gmega
a68de9fe17
Merge branch 'master' into feature/profiler-v4 2024-01-31 11:20:38 -03:00
gmega
f007e1b0fd
initial port of profiler to Chronos V4 2024-01-31 11:17:33 -03:00
Jacek Sieka
672db137b7
v4.0.0 (#494)
Features:

* Exception effects / raises for async procedures helping you write more
efficient leak-free code
* Cross-thread notification mechanism for suitable building channels,
queues and other multithreaded primitives
* Async process I/O
* IPv6 dual stack support
* HTTP middleware support alloing multiple services to share a single
http server
* A new [documentation web
site](https://status-im.github.io/nim-chronos/) covering the basics,
with several simple examples for getting started
* Implicit returns, support for `results.?` and other conveniences
* Rate limiter
* Revamped cancellation support with more control over the cancellation
process
* Efficiency improvements with `lent` and `sink`

See the [porting](https://status-im.github.io/nim-chronos/porting.html)
guides for porting code from earlier chronos releases (as well as
asyncdispatch)
v4.0.0
2024-01-24 19:33:13 +02:00
Eugene Kabanov
09a0b11719
Make asyncproc use asyncraises. (#497)
* Make asyncproc use asyncraises.

* Fix missing asyncraises for waitForExit().
2024-01-23 08:34:10 +01:00
gmega
4916381aa0
Merge branch 'master' into feature/profiler-v4 2024-01-22 14:36:18 -03:00
Jacek Sieka
e296ae30c8
asyncraises for threadsync (#495)
* asyncraises for threadsync

* missing bracket

* missing exception
2024-01-20 16:56:57 +01:00
Jacek Sieka
3ca2c5e6b5
deprecate callback=, UDP fixes (fixes #491) (#492)
Using the callback setter may lead to callbacks owned by others being
reset, which is unexpected.

* don't crash on zero-length UDP writes
2024-01-19 09:21:10 +01:00
Jacek Sieka
1021a7d294
check leaks after every test (#487) 2024-01-18 14:34:16 +02:00
cheatfate
92acf68b04
Fix examples documentation. 2024-01-12 15:39:45 +02:00
Eugene Kabanov
b02b9608c3
HTTP server middleware implementation. (#483)
* HTTP server middleware implementation and test.

* Address review comments.

* Address review comments.
2024-01-12 15:27:36 +02:00
Jacek Sieka
f0a2d4df61
Feature flag for raises support (#488)
Feature flags allow consumers of chronos to target versions with and
without certain features via compile-time selection. The first feature
flag added is for raise tracking support.
2024-01-08 14:54:50 +01:00
Jacek Sieka
e15dc3b41f
prevent http closeWait future from being cancelled (#486)
* 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
2024-01-04 16:17:42 +01:00
Jacek Sieka
41f77d261e
Better line information on effect violation
We can capture the line info from the original future source and direct
violation errors there
2023-12-27 20:57:39 +01:00
Jacek Sieka
1598471ed2
add a test for results.? compatibility (#484)
Finally! (haha)
2023-12-21 15:52:16 +01:00
Eugene Kabanov
c41599a6d6
Asyncraises HTTP layer V3 (#482)
* No Critical and Recoverable errors anymore.

* Recover raiseHttpCriticalError()

* Post-rebase fixes.

* Remove deprecated ResponseFence and getResponseFence().

* HttpProcessCallback and 2.

* Fix callback holder.

* Fix test issue.

* Fix backwards compatibility of `HttpResponse.state` field.
2023-12-09 06:50:35 +02:00
gmega
c960f96be8
rename states and callbacks to reflect current domain understanding 2023-12-08 11:33:58 -03:00
gmega
7474c5238d
remove profiler export from main module; disable profiler in tests by default 2023-12-08 10:21:08 -03:00
gmega
eb7cf1ae1b
enable profiling on testprofiler; import/export profiler from chronos's root module 2023-12-07 18:53:12 -03:00
gmega
321b6c7024
capitalize test suite names to make it consistent with the rest 2023-12-07 17:11:27 -03:00
gmega
8ffe7f4a88
improve assertion error messages 2023-12-07 17:10:17 -03:00
gmega
5d27b12b17
move instrumentation points for async future FSM into more correct locations 2023-12-07 17:09:45 -03:00
Jacek Sieka
e38ceb5378
fix v3 backwards compatibility for callbacks (#481)
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.
2023-12-04 14:19:29 +01:00
gmega
3f774a1fa4
enable future ID; add extra debug info 2023-12-01 18:41:50 -03:00
Jacek Sieka
48b2b08cfb
Update docs (#480)
* new mdbook version with built-in Nim highlighting support
* describe examples in a dedicated page
* fixes
2023-12-01 12:33:28 +01:00
gmega
9883d7dd8a
add zombie checks to run state too 2023-11-29 13:30:15 -03:00
gmega
9f9b31450e
add zombie track test, strenghten zombie event spec test 2023-11-29 12:18:57 -03:00
gmega
b64014c154
remove example file (included by accident) 2023-11-29 09:52:32 -03:00
gmega
ade1f3018e
add failing test case for an async proc with children in its finally block 2023-11-28 18:47:43 -03:00
Eugene Kabanov
28a100b135
Fix processing callback missing asyncraises. (#479) 2023-11-28 18:57:13 +02:00
gmega
1d5d02cfa4
add location info to assertions to make them easier to trace 2023-11-28 09:17:58 -03:00
gmega
128531cd83
add accessor to exec time + children, type aliases, minor refactor 2023-11-27 18:08:08 -03:00
gmega
d80fa15233
add call count and max exec time; rename enable => enableProfiling to clear up intent 2023-11-27 14:11:06 -03:00
gmega
d320e2ab09
change enable flag to "chronosProfiling"; add "enable" profiler proc; add stronger assertions to event tests" 2023-11-27 12:27:14 -03:00
gmega
e65c48c153
add tests for exceptions, cancellation, and multiple pauses 2023-11-27 10:58:07 -03:00
gmega
a5fb393ad8
add test for future with a single non-blocking child 2023-11-27 09:52:41 -03:00
gmega
ce1e03aa4e
add test for simple non-blocking future 2023-11-27 09:49:44 -03:00
gmega
81711f8b11
add support for blocking children 2023-11-24 19:46:19 -03:00
gmega
8b5c6a4674
add harness for simulating profiled time and basic profiler metric test 2023-11-24 15:19:01 -03:00
gmega
d4809d5a98
add harness and initial test 2023-11-22 19:31:42 -03:00
Eugene Kabanov
b18d471629
Asyncraises HTTP client/server. (#476)
* 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>
2023-11-21 11:01:44 +01:00
Jacek Sieka
fa0bf405e6
varargs overloads (#477)
* varargs overloads

for convenience and compatibility

* no parameterless varargs calls with generic overloads
2023-11-20 12:04:28 +02:00
Jacek Sieka
f03cdfcc40
futures: sinkify (#475)
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.
2023-11-19 18:29:09 +01:00
Eugene Kabanov
0b136b33c8
Asyncstreams asyncraises. (#472)
* 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.
2023-11-17 23:18:09 +01:00
Jacek Sieka
1306170255
dedicated exceptions for Future.read failures (#474)
Dedicated exceptions for `read` failures reduce the risk of mixing up
"user" exceptions with those of Future itself. The risk still exists, if
the user allows a chronos exception to bubble up explicitly.

Because `await` structurally guarantees that the Future is not `pending`
at the time of `read`, it does not raise this new exception.

* introduce `FuturePendingError` and `FutureCompletedError` when
`read`:ing a future of uncertain state
* fix `waitFor` / `read` to return `lent` values
* simplify code generation for `void`-returning async procs
* document `Raising` type helper
2023-11-17 13:45:17 +01:00
Jacek Sieka
f5ff9e32ca
introduce asyncraises in transports/asyncsync (#470)
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`)
2023-11-15 09:38:48 +01:00
Jacek Sieka
24be151cf3
move docs to docs (#466)
* introduce user guide based on `mdbook`
* set up structure for adding simple `chronos` usage examples
* move most readme content to book
* ci deploys book and api guide automatically
* remove most of existing engine docs (obsolete)
2023-11-15 09:06:37 +01:00
Eugene Kabanov
9c93ab48de
Attempt to fix CI crash at Windows. (#465)
* Attempt to fix CI crash at Windows.
Remove all cast[string] and cast[seq[byte]] from the codebase.

* Address review comments.
2023-11-13 13:14:21 +02:00
Jacek Sieka
0d55475c29
stew/results -> results (#468) 2023-11-13 10:56:19 +01:00
Jacek Sieka
f0eb7a0ae9
simplify tests (#469)
* simplify tests

`chronosPreviewV4` is obsolete

* oops
2023-11-13 10:54:37 +01:00
Eugene Kabanov
8156e2997a
Fix not enough memory on i386. (#467)
* Fix waitFor() should not exit earlier last callback will be scheduled.

* Tune tests to use less memory.

* Fix `testutils`. There is no more last poll() needed.

* Update chronos/internal/asyncfutures.nim

---------

Co-authored-by: Jacek Sieka <jacek@status.im>
2023-11-10 07:42:36 +01:00