104 Commits
Author SHA1 Message Date
nagachika 2b2ab1a67c merge revision(s) 08b3a45bc9: [Backport #21180]
Push a real iseq in rb_vm_push_frame_fname()

	Previously, vm_make_env_each() (used during proc
	creation and for the debug inspector C API) picked up the
	non-GC-allocated iseq that rb_vm_push_frame_fname() creates,
	which led to a SEGV when the GC tried to mark the non GC object.

	Put a real iseq imemo instead. Speed should be about the same since
	the old code also did a imemo allocation and a malloc allocation.

	Real iseq allows ironing out the special-casing of dummy frames in
	rb_execution_context_mark() and rb_execution_context_update(). A check
	is added to RubyVM::ISeq#eval, though, to stop attempts to run dummy
	iseqs.

	[Bug #21180]

	Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2025-03-16 18:52:56 +09:00
Takashi Kokubun f19831a15d merge revision(s) a8c2d5e7be: [Backport #20907]
Ensure fiber scheduler re-acquires mutex when interrupted from sleep. (#12158)

	[Bug #20907]
2025-01-14 17:47:41 -08:00
KJ Tsanaktsidis 5b6009870d Ensure fiber scheduler is woken up when close interrupts read
If one thread is reading and another closes that socket, the close
blocks waiting for the read to abort cleanly. This ensures that Ruby is
totally done with the file descriptor _BEFORE_ we tell the OS to close
and potentially re-use it.

When the read is correctly terminated, the close should be unblocked.
That currently works if closing is happening on a thread, but if it's
happening on a fiber with a fiber scheduler, it does NOT work.

This patch ensures that if the close happened in a fiber scheduled
thread, that the scheduler is notified that the fiber is unblocked.

[Bug #20723]
2024-09-23 09:25:10 -07:00
Takashi Kokubun 5688bcb54a merge revision(s) 5d1702e01a: [Backport #20413]
Enumerator should use a non-blocking fiber, change `rb_fiber_new` to be non-blocking by default. (#10481)
2024-05-29 15:43:01 -07:00
Misaki Shioi 52f6de4196 Replace SocketError with Socket::ResolutionError in rsock_raise_socket_error
rsock_raise_socket_error is called only when getaddrinfo and getaddrname fail
2023-11-30 13:27:19 +09:00
Jun Aruga 3eaae72855 test/fiber/test_queue.rb: Make the stuck test fail. (#8791)
test/fiber/test_queue.rb: Make the stuck tests fail.

We observed the 2 tests in the `test/fiber/test_queue.rb` getting stuck
in some GCC compilers in Ubuntu ppc64le focal/jammy, even when the timeout
`queue.pop(timeout: 0.0001)` is set in the code.

This commit is to make the tests fail rather than getting stuck.
2023-10-28 11:10:30 +02:00
Nobuyoshi Nakada ab637cad2b [Bug #19624] Clean up backquote IO
It should not be hidden, since it can be grabbed by a fiber scheduler.
2023-09-21 10:23:14 +09:00
Samuel Williams 05aaff2191 Reduce number of iterations in TestFiberScheduler#test_autoload. (#8391)
`ppc64le` appears to be struggling with this test due to timeout. Let's see
if reducing the number of iterations can help improve the test performance.
2023-09-07 13:53:51 +12:00
Samuel Williams 901b6d9c50 Validate the typed data before dereferencing the internal struct. (#8315) 2023-08-29 20:04:14 +12:00
Nobuyoshi Nakada 5dd969892f Wait for sleepr thread to finish not to leak 2023-07-13 13:12:52 +09:00
Samuel Williams 0402193723 Fix Thread#join(timeout) when running inside the fiber scheduler. (#7903) 2023-06-03 12:41:36 +09:00
Samuel Williams 0b2613f443 rb_io_puts should not write zero length strings. (#7806) 2023-05-15 11:13:51 +09:00
Samuel Williams 648870b5c5 Support IO#pread / IO#pwrite using fiber scheduler. (#7594)
* Skip test if non-blocking file IO is not supported.
2023-03-31 00:48:55 +13:00
Samuel Williams 466aa8010f Fix incorrect usage of rb_fiber_scheduler_io_(p)(read|write). (#7593) 2023-03-25 18:36:27 +13:00
Samuel Williams 7abe47b85a Improve robustness of io_wait implementation. (#7456)
- Restore correct handling of `duration`.
- Don't delete from `@readable` or `@writable` unless it was added.
- A little more documentation.
2023-03-07 19:38:58 +13:00
Benoit Daloze 0efa36ac06 Ensure Fiber storage is only accessed from the Fiber it belongs to 2022-12-20 19:32:23 +01:00
Benoit Daloze d557f17974 Use an experimental warning for Fiber#storage= 2022-12-20 19:32:23 +01:00
Benoit Daloze 45175962a6 Never use the storage of another Fiber, that violates the whole design
* See https://bugs.ruby-lang.org/issues/19078#note-30
2022-12-20 19:32:23 +01:00
Samuel Williams 9da5a7e79d Add tests for Queue#pop with fiber scheduler. (#6953) 2022-12-17 20:43:21 +13:00
Nobuyoshi Nakada bb0ec7df32 Wait killed threads 2022-12-02 23:46:21 +09:00
Samuel Williams 0436f1e15a Introduce Fiber#storage for inheritable fiber-scoped variables. (#6612) 2022-12-01 23:00:33 +13:00
Samuel WilliamsandLars Kanis ea8a7287e2 Add support for sockaddr_un on Windows. (#6513)
* Windows: Fix warning about undefined if_indextoname()

* Windows: Fix UNIXSocket on MINGW and make .pair more reliable

* Windows: Use nonblock=true for read tests with scheduler

* Windows: Move socket detection from File.socket? to File.stat

Add S_IFSOCK to Windows and interpret reparse points accordingly.
Enable tests that work now.

* Windows: Use wide-char functions to UNIXSocket

This fixes behaviour with non-ASCII characters.
It also fixes deletion of temporary UNIXSocket.pair files.

* Windows: Add UNIXSocket tests for specifics of Windows impl.

* Windows: fix VC build due to missing _snwprintf

Avoid usage of _snwprintf, since it fails linking ruby.dll like so:

  linking shared-library x64-vcruntime140-ruby320.dll
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf
  x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l

whereas linking miniruby.exe succeeds.

This patch uses snprintf on the UTF-8 string instead.

Also remove branch GetWindowsDirectoryW, since it doesn't work.

* Windows: Fix dangling symlink test failures

Co-authored-by: Lars Kanis <kanis@comcard.de>
2022-11-17 14:50:25 -08:00
Jean byroot BoussierandJean Boussier eacedcfe44 mutex: Raise a ThreadError when detecting a fiber deadlock (#6680)
[Bug #19105]

If no fiber scheduler is registered and the fiber that
owns the lock and the one that try to acquire it
both belong to the same thread, we're in a deadlock case.

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2022-11-09 00:43:16 +13:00
Samuel Williams 16953867ed We don't care about actual hostname resolution. (#6652)
https://bugs.ruby-lang.org/issues/18380
2022-11-01 17:10:31 +13:00
Samuel Williams 7f175e5648 Avoid missed wakeup with fiber scheduler and Fiber.blocking. (#6588)
* Ensure that blocked fibers don't prevent valid wakeups.
2022-10-20 13:38:52 +13:00
Samuel Williams 8a420670a2 Introduce Fiber::Scheduler#io_select hook for non-blocking IO.select. (#6559) 2022-10-15 19:59:04 +13:00
Samuel Williams 765ee822b5 Add missing f.resume to fiber test. (#6539) 2022-10-13 19:04:06 +13:00
Samuel Williams 04d291a490 Simplify implementation of scheduler io_read and io_write. (#6527) 2022-10-12 15:56:35 +13:00
Samuel Williams ced1d17280 Improvements to IO::Buffer implementation and documentation. (#6525) 2022-10-12 12:59:05 +13:00
Samuel Williams e696ec67ac Introduce Fiber.blocking{} for bypassing the fiber scheduler. (#6498) 2022-10-06 23:00:49 +13:00
Samuel Williams 42bcc629fb Retain reference to blocking fibers. 2022-05-25 15:24:24 +12:00
Yusuke Endoh df0bcb3385 test/fiber/test_scheduler.rb: Remove the test file from $LOADED_FEATURES
to prevent the following failure on `make test-all --repeat-count=2`

http://ci.rvm.jp/results/trunk-repeat20-asserts@phosphorus-docker/3957774
```
  1) Error:
TestFiberScheduler#test_autoload:
NameError: uninitialized constant TestFiberSchedulerAutoload
          Object.const_get(:TestFiberSchedulerAutoload)
                ^^^^^^^^^^
```
2022-05-09 10:20:25 +09:00
Samuel Williams fd6cef79f5 Use a proper mutex for autoloading features. (#5788)
Object#autoload implements a custom per-thread "mutex" for blocking
threads waiting on autoloading a feature. This causes problems when used
with the fiber scheduler. We swap the implementation to use a Ruby mutex
which is fiber aware.
2022-05-08 10:22:58 +12:00
Nobuyoshi Nakada d650b17686 rb_fiber_terminate must not return [Bug #18497]
In a forked process from a fiber, the fiber becomes the only
fiber, `fiber_switch` does nothing as there is no other fibers,
`rb_fiber_terminate` does not terminate the fiber.  In that case,
reaches the end of `fiber_entry` finaly, which is declared as
"COROUTINE" and should never return.
2022-01-19 19:57:16 +09:00
Hiroshi SHIBATA f95039af75 Use omit instead of skip without the default gems tests 2022-01-11 21:17:59 +09:00
Samuel Williams 9fbf94ff04 Improve interface for get/set/copy. 2021-12-21 12:25:42 +13:00
Kazuki Yamaguchi 6b67f06312 test/fiber/test_io_buffer.rb: fix file descriptor leaks
I got the warning while running "make test-all":

	Leaked file descriptor: TestFiberIOBuffer#test_write_nonblock: 9 : #<UNIXSocket:fd 9>
	Closed file descriptor: TestFiberIOBuffer#test_read_write_blocking: 9
	Leaked file descriptor: TestFiberIOBuffer#test_timeout_after: 10 : #<UNIXSocket:fd 10>
	Closed file descriptor: TestFiberIOBuffer#test_read_nonblock: 10
2021-12-21 00:05:24 +09:00
Samuel Williams 42d3231154 Introduce io_result wrapper for passing [-errno, size] in VALUE. 2021-12-18 18:19:30 +13:00
Nobuyoshi Nakada a88b19d3d0 Suppress the “experimental" warnings for IO::Buffer
As this warning is emitted just once per processes, needs in each
files when parallel testing.
2021-11-23 16:08:53 +09:00
Samuel Williams 81d0ce7e97 Mark IO::Buffer as experimental. 2021-11-10 19:21:05 +13:00
Samuel Williams cb8434563d Add alternative optional hook for scheduler_close to allow public usage of close. 2021-09-20 22:07:58 +12:00
Lars Kanis 9c0582704f Fix example fiber scheduler reg. writable events
There were two issues:

1. When an IO object is waiting for writablility only (as in test_tcp_accept) the selected hash is empty.
   Therefore selected[fiber] returns nil but needs to default to 0 in order to be or'ed with IO::WRITABLE.

2. When an IO object is waiting for read- or writability (as in test_tcp_connect), but only one of these
   two events arrive, the Fiber and IO object need to be removed from the other `@readable` or `@writable` list.
2021-08-26 21:49:12 +12:00
Samuel Williams 2d4f29e77e Fix potential hang when joining threads.
If the thread termination invokes user code after `th->status` becomes
`THREAD_KILLED`, and the user unblock function causes that `th->status` to
become something else (e.g. `THREAD_RUNNING`), threads waiting in
`thread_join_sleep` will hang forever. We move the unblock function call
to before the thread status is updated, and allow threads to join as soon
as `th->value` becomes defined.

This reverts commit 6505c77501.
2021-08-03 22:23:48 +12:00
Yusuke Endoh 6505c77501 Revert "Fix potential hang when joining threads."
This reverts commit 13f8521c63.

http://rubyci.s3.amazonaws.com/solaris11-gcc/ruby-master/log/20210727T230009Z.fail.html.gz
http://rubyci.s3.amazonaws.com/solaris11-sunc/ruby-master/log/20210728T000009Z.fail.html.gz

This revert is to confirm whether the commit is the cause.
If the failures consistently occur after this revert, I'll
reintroduce the commit.
2021-07-28 11:05:36 +09:00
Samuel Williams 13f8521c63 Fix potential hang when joining threads.
If the thread termination invokes user code after `th->status` becomes
`THREAD_KILLED`, and the user unblock function causes that `th->status` to
become something else (e.g. `THREAD_RUNNING`), threads waiting in
`thread_join_sleep` will hang forever. We move the unblock function call
to before the thread status is updated, and allow threads to join as soon
as `th->value` becomes defined.
2021-07-27 18:23:30 +12:00
Nobuyoshi Nakada 9eae8cdefb Prefer qualified names under Thread 2021-06-29 11:41:10 +09:00
Nobuyoshi Nakada edbe0e224c Suppress exception report in inner thread 2021-06-15 00:03:05 +09:00
Nobuyoshi Nakada 57eaa07ba6 Close leaked file descriptors 2021-06-15 00:02:15 +09:00
Bruno Sutic 1ab71a5b98 Fix fiber scheduler address resolve solaris tests 2021-06-14 22:09:23 +12:00
Samuel Williams 050a895439 Wake up join list within thread EC context. (#4471)
* Wake up join list within thread EC context.

* Consume items from join list so that they are not re-executed.

If `rb_fiber_scheduler_unblock` raises an exception, it can result in a
segfault if `rb_threadptr_join_list_wakeup` is not within a valid EC. This
change moves `rb_threadptr_join_list_wakeup` into the thread's top level EC
which initially caused an infinite loop because on exception will retry. We
explicitly remove items from the thread's join list to avoid this situation.

* Verify the required scheduler interface.

* Test several scheduler hooks methods with broken `unblock` implementation.
2021-06-14 17:56:53 +12:00