Commit 5ce4df0
authored
Add synchronous blocking channel receive (#23)
* Add synchronous blocking channel receive
Implement blocking receive for channels that suspends Python while
waiting for data and releases the dirty scheduler worker.
- Add sync_waiter_pid and has_sync_waiter fields to py_channel_t
- Add channel_register_sync_waiter NIF to register calling process
- Modify channel_send to notify sync waiter via Erlang message
- Modify channel_close to notify sync waiter of channel closure
- Implement blocking handle_receive using Erlang receive to wait
- Add tests for immediate, delayed, and closed channel cases
* Add async receive e2e test to verify asyncio integration
* Add subinterpreter mode sync receive test
Test verifies blocking channel receive works with Python 3.12+
subinterpreter contexts. Skips gracefully on older Python versions.
* Fix subinterp_sync_receive_wait_test to be proper e2e test
- Use py_context:start_link/2 with unique integer ID
- Use py_context:stop/1 instead of gen_server:stop
- Test immediate receive, blocking receive with delayed send,
try_receive on empty, and closed channel detection
* Fix race condition and cleanup in sync waiter registration
- Check if data is available when registering sync waiter to handle race
between try_receive returning empty and register_sync_waiter being called
- Return 'has_data' atom when data arrived in the window, caller retries
- Notify sync waiter in channel destructor when channel is GC'd
- Do not notify async waiter in destructor to avoid use-after-free when
event loop is destroyed concurrently
- Update test to consume data before re-registering waiter
* Remove unused ChannelBuffer Python type
The ChannelBuffer type was defined but never used. Removing dead code.
* Fix channel waiter race conditions and lost wakeups
- Reject duplicate/mixed waiters: both async and sync waiter registration
now return {error, waiter_exists} if any waiter already exists
- Fix lost wakeups: event_loop_add_pending now returns bool; waiter state
is only cleared after successful dispatch
- Add null checks for enif_alloc_env in sync waiter notifications
- Add tests for mixed waiter rejection scenarios
* Remove deprecated ASGI/WSGI NIF tests, keep deprecation checks
The asgi_run and wsgi_run NIF functions are deprecated. Removed tests
that call these functions, keeping only the deprecation attribute tests.
* Fix use-after-free in tl_pending_args across subinterpreters
Clear tl_pending_args to NULL whenever tl_pending_callback is set to
false. Previously, the thread-local pointer was left dangling after
callback completion. When a dirty scheduler thread later handled a
different subinterpreter's code, Py_XDECREF on the stale pointer
would attempt to free memory from the wrong allocator.1 parent 2c02500 commit 5ce4df0
File tree
11 files changed
+613
-450
lines changed- c_src
- src
- test
11 files changed
+613
-450
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
566 | 567 | | |
567 | 568 | | |
568 | 569 | | |
| |||
575 | 576 | | |
576 | 577 | | |
577 | 578 | | |
| 579 | + | |
578 | 580 | | |
579 | 581 | | |
580 | 582 | | |
| |||
610 | 612 | | |
611 | 613 | | |
612 | 614 | | |
| 615 | + | |
613 | 616 | | |
614 | 617 | | |
615 | 618 | | |
| |||
811 | 814 | | |
812 | 815 | | |
813 | 816 | | |
| 817 | + | |
814 | 818 | | |
815 | 819 | | |
816 | 820 | | |
| |||
1290 | 1294 | | |
1291 | 1295 | | |
1292 | 1296 | | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
1293 | 1310 | | |
1294 | 1311 | | |
1295 | 1312 | | |
| |||
1553 | 1570 | | |
1554 | 1571 | | |
1555 | 1572 | | |
| 1573 | + | |
1556 | 1574 | | |
1557 | 1575 | | |
1558 | 1576 | | |
| |||
1561 | 1579 | | |
1562 | 1580 | | |
1563 | 1581 | | |
1564 | | - | |
1565 | | - | |
1566 | | - | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
1567 | 1588 | | |
1568 | 1589 | | |
1569 | 1590 | | |
| |||
2649 | 2670 | | |
2650 | 2671 | | |
2651 | 2672 | | |
| 2673 | + | |
2652 | 2674 | | |
2653 | 2675 | | |
2654 | 2676 | | |
| |||
2717 | 2739 | | |
2718 | 2740 | | |
2719 | 2741 | | |
| 2742 | + | |
2720 | 2743 | | |
2721 | 2744 | | |
2722 | 2745 | | |
| |||
0 commit comments