26 Commits

Author SHA1 Message Date
Jingyu Zhou
2d2a2144f4 Update copyright years to 2013-2026 (#12653)
No functional changes.
2026-01-22 10:49:41 -08:00
Jingyu Zhou
786154f07e Fix unseed mismatch in newly added tests (#12505)
/flow/IThreadPool/ tests are non-deterministic.

Seed: -f tests/fast/RandomUnitTests.toml -s 2889898182 -b on
commit: 841e1e1b47
2025-10-23 15:44:51 -07:00
zhscn
98241ec2ba Fix double free error in ThreadPool (#12473)
* Fix double free error in ThreadPool
* Test cases to verify the correct destruction of the IThreadPool
2025-10-20 21:58:49 -07:00
Vishesh Yadav
04b4619bca ThreadReturnPromiseStream: Re-write to use thread-safe primitives
The original `ThreadReturnPromiseStream` had a fundamental flaw: it didn't handle reference counting
in a thread-safe way. This led to subtle and hard-to-debug race conditions, especially since Future
and Promise often live on different threads in this use case.

This patch introduces a new implementation of ThreadReturnPromiseStream that uses an atomics backed
spinlock to safely manage reference counts. As a result, the Flow compiler also needs to support a
new type: `ThreadFutureStream`, in addition to the existing `FutureStream`.

The underlying `NotifiedQueue` now has a parallel implementation called `ThreadNotifiedQueue` to
make this possible. The higher-level thread-safe promise and promise counterpart are built on top of
that.

The new `ThreadFutureStream` is compatible with both Flow and C++ coroutines. The original
non-threaded Flow primitives remain untouched and free from the overhead of atomics.

Joshua:
  20250417-000356-vishesh-16ce18efeab40158           compressed=True data_size=41124943 duration=5436274 ended=99998 fail=1 fail_fast=10 max_runs=100000 pass=99997 priority=100 remaining=0:00:00 runtime=1:00:47 sanity=False started=100000 submitted=20250417-000356 timeout=5400 username=vishesh

clang-format
2025-04-25 16:45:57 -07:00
Michael Stack
1d03904ea3 Revert "Hold ThreadReturnPromiseStream reference when sending value/error" (#12050)
We crash with rocksdb storage when bulkloading at scale
with this change in place. Removing for now.

This reverts commit 55edaf5ed1.

Co-authored-by: stack <stack@duboce.com>
2025-03-25 14:55:09 -07:00
Vishesh Yadav
bc4dec8e5d Fix use-after-move issue in AsyncTaskExecutor
`getFuture()` should be called before post as `send`/`sendError`
operation in `ThreadReturnPromise` moves the underlying Promise to
`tagAndForward()`.

Ideally, `ThreadReturnPromise` behavior should stay consistent with the
`Promise`. However, the problem is that it relies on the invariant that
there will always be one owner of its internal `Promise` which is either
itself or `tagOrForward`  -- which is necessary to ensure that only one
thread can operate on the Promise's internal state (ref count, flags
etc) and avoid race conditions.

This patch (1) makes sure that in case of `post()` function we get
future before, (2) adds an ASSERT as this should never happen, (3)
documentation for future users and (4) a test case for potentially
fixing this in future.
2025-03-14 14:11:22 -07:00
Vishesh Yadav
55edaf5ed1 Hold ThreadReturnPromiseStream reference when sending value/error
When a value/error is sent via `ThreadReturnPromiseStream` we assume that the underlying
`PromiseStream` will be alive when the client waits. However, if the last
`ThreadReturnPromiseStream` gets destroyed after sending values/end_of_stream(), the underlying
`PromiseStream` will as well resulting in `broken_promise`. This happens because the actual work of
sending the value/error is deferred on the main thread.

This is likely to happen because the sender did its work and it isn't supposed to check if client
got the value. Hence, little reason to keep the promise. Meanwhile, client is free to read values
from its future whenever it needs to.

This patch just holds the reference to underlying `NotifiedQueue` by copying `PromiseStream` until
the value/error is sent. The test added would fail without this patch.
2025-03-06 02:00:34 -08:00
Syed Paymaan Raza
c3e7542cda Update end year in copyright header 2024-08-02 09:40:11 -07:00
Xiaoge Su
c11c48fa3f Extract ChaosMetrics out from network.h 2023-01-24 14:47:48 -08:00
sfc-gh-tclinkenbeard
1aabbb07d2 Add missing copyright headers 2022-03-16 11:25:02 -07:00
Yao Xiao
c605226a56 Add error handling in RocksDB KVS. (#6277) 2022-01-25 13:59:25 -08:00
helium
f445d94baf Comments resolved. 2021-08-11 17:01:12 -07:00
helium
e988ac53d9 clang-format 2021-08-11 16:21:06 -07:00
helium
c043b21974 Added test for sending error 2021-08-11 11:37:12 -07:00
helium
f8edf6e1f2 Switched to a separate test ThreadPoolReceiver 2021-08-11 10:47:51 -07:00
helium
15d050ece5 Added unit test, and bug fixes. 2021-08-09 16:26:29 -07:00
sfc-gh-tclinkenbeard
f4d03562f4 Merge remote-tracking branch 'origin/master' into fix-clang-warnings 2021-07-26 13:38:36 -07:00
Mohamed Oulmahdi
c405bb5cd0 Fix flow build issue on Windows 2021-07-23 12:03:25 +02:00
sfc-gh-tclinkenbeard
e62e6503ac Fix most delete-non-virtual-dtor clang warnings 2021-07-21 23:32:44 -07:00
Markus Pilman
8f6b048e22 fix macOS build 2021-07-20 11:52:57 -06:00
Daniel Smith
acfd0b6c1c Don't check the random number generator state at the end 2021-07-08 19:19:02 -04:00
Daniel Smith
3fbd6b6143 Enable IThreadPool in simulation 2021-07-08 18:51:01 -04:00
Daniel Smith
0df49e1bee Run IThreadPool naming test outside simulation 2021-06-30 15:06:58 -04:00
Daniel Smith
299eaef858 Update flow/IThreadPoolTest.actor.cpp
Co-authored-by: A.J. Beamon <aj.beamon@snowflake.com>
2021-06-29 16:39:50 -04:00
Daniel Smith
ac01e5bcfd Update flow/IThreadPoolTest.actor.cpp
Co-authored-by: A.J. Beamon <aj.beamon@snowflake.com>
2021-06-29 16:37:06 -04:00
Daniel Smith
f58c7fd8bc Fix IThreadPool thread naming 2021-06-29 16:27:37 -04:00