ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:117453] [Ruby master Bug#20413] Enumerator can block fiber scheduler.
@ 2024-04-07 10:47 ioquatix (Samuel Williams) via ruby-core
  2024-04-07 11:16 ` [ruby-core:117454] " Eregon (Benoit Daloze) via ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2024-04-07 10:47 UTC (permalink / raw
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #20413 has been reported by ioquatix (Samuel Williams).

----------------------------------------
Bug #20413: Enumerator can block fiber scheduler.
https://bugs.ruby-lang.org/issues/20413

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
Using `Enumerator` in the event loop can cause problems as the fiber created by `rb_fiber_new` is blocking by default. It should be non-blocking.

See <https://github.com/ruby/ruby/pull/10478> for the fix.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:117454] [Ruby master Bug#20413] Enumerator can block fiber scheduler.
  2024-04-07 10:47 [ruby-core:117453] [Ruby master Bug#20413] Enumerator can block fiber scheduler ioquatix (Samuel Williams) via ruby-core
@ 2024-04-07 11:16 ` Eregon (Benoit Daloze) via ruby-core
  2024-04-07 11:57 ` [ruby-core:117455] " ioquatix (Samuel Williams) via ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-04-07 11:16 UTC (permalink / raw
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #20413 has been updated by Eregon (Benoit Daloze).


Changing `rb_fiber_new` sounds incompatible: https://github.com/ruby/ruby/pull/10481#issuecomment-2041432435
Changing Enumerator fibers would be safer, but probably still incompatible.

What is the use-case here, to use an Enumerator backed by a Fiber (so `next`/`peek`) in a Fiber scheduler?

----------------------------------------
Bug #20413: Enumerator can block fiber scheduler.
https://bugs.ruby-lang.org/issues/20413#change-107838

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
Using `Enumerator` in the event loop can cause problems as the fiber created by `rb_fiber_new` is blocking by default. It should be non-blocking.

See <https://github.com/ruby/ruby/pull/10481> for the fix.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:117455] [Ruby master Bug#20413] Enumerator can block fiber scheduler.
  2024-04-07 10:47 [ruby-core:117453] [Ruby master Bug#20413] Enumerator can block fiber scheduler ioquatix (Samuel Williams) via ruby-core
  2024-04-07 11:16 ` [ruby-core:117454] " Eregon (Benoit Daloze) via ruby-core
@ 2024-04-07 11:57 ` ioquatix (Samuel Williams) via ruby-core
  2024-04-07 12:48 ` [ruby-core:117456] " ioquatix (Samuel Williams) via ruby-core
  2024-05-29 22:43 ` [ruby-core:118074] " k0kubun (Takashi Kokubun) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2024-04-07 11:57 UTC (permalink / raw
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #20413 has been updated by ioquatix (Samuel Williams).


> What is the use-case here, to use an Enumerator backed by a Fiber (so next/peek) in a Fiber scheduler?

Yes.

> Changing Enumerator fibers would be safer, but probably still incompatible.

Can you show evidence where this breaks some existing test or program?

The fiber scheduler is transparent to user code, so there shouldn't be any incompatibility. Additionally, `Fiber.new` adopted this a while ago and there have been no issues. `Fiber.new` is arguably more widely used than `rb_fiber_new`.

----------------------------------------
Bug #20413: Enumerator can block fiber scheduler.
https://bugs.ruby-lang.org/issues/20413#change-107839

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
Using `Enumerator` in the event loop can cause problems as the fiber created by `rb_fiber_new` is blocking by default. It should be non-blocking.

See <https://github.com/ruby/ruby/pull/10481> for the fix.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:117456] [Ruby master Bug#20413] Enumerator can block fiber scheduler.
  2024-04-07 10:47 [ruby-core:117453] [Ruby master Bug#20413] Enumerator can block fiber scheduler ioquatix (Samuel Williams) via ruby-core
  2024-04-07 11:16 ` [ruby-core:117454] " Eregon (Benoit Daloze) via ruby-core
  2024-04-07 11:57 ` [ruby-core:117455] " ioquatix (Samuel Williams) via ruby-core
@ 2024-04-07 12:48 ` ioquatix (Samuel Williams) via ruby-core
  2024-05-29 22:43 ` [ruby-core:118074] " k0kubun (Takashi Kokubun) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2024-04-07 12:48 UTC (permalink / raw
  To: ruby-core; +Cc: ioquatix (Samuel Williams)

Issue #20413 has been updated by ioquatix (Samuel Williams).


After discussing it with Eregon on Slack, he withdrew his objection to this change.

In general, this change:

- Aligns `Fiber.new` with `rb_fiber_new` so that they both produce non-blocking fibers.
- Doesn't affect existing code, as there is no obvious usage of `rb_fiber_new` by GitHub code search (small/zero blast radius).
- Only impacts usage within the fiber scheduler, i.e. no effect outside of fiber scheduler beside the predicate value itself.
- Even within the fiber scheduler, it is transparent to user code.

----------------------------------------
Bug #20413: Enumerator can block fiber scheduler.
https://bugs.ruby-lang.org/issues/20413#change-107841

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
Using `Enumerator` in the event loop can cause problems as the fiber created by `rb_fiber_new` is blocking by default. It should be non-blocking.

```ruby
#!/usr/bin/env ruby

require 'async'

Async do
  Async do
    while true
      puts "Hello"
      sleep 1
    end
  end
  
  enumerator = Enumerator.new do |yielder|
    while true
      yielder << "World"
      sleep 1
    end
  end
  
  while true
    puts enumerator.next
  end
end
```

Before this PR, the output is:

```
> ./test.rb
Hello
World
World
World
World
World
World
...
```

After this PR, the output is:

```
> ./test.rb
Hello
World
Hello
World
Hello
World
Hello
World
Hello
World
...
```

The reason why this happens, is because the enumerator `sleep` never yields to the event loop.

See <https://github.com/ruby/ruby/pull/10481> for the fix.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:118074] [Ruby master Bug#20413] Enumerator can block fiber scheduler.
  2024-04-07 10:47 [ruby-core:117453] [Ruby master Bug#20413] Enumerator can block fiber scheduler ioquatix (Samuel Williams) via ruby-core
                   ` (2 preceding siblings ...)
  2024-04-07 12:48 ` [ruby-core:117456] " ioquatix (Samuel Williams) via ruby-core
@ 2024-05-29 22:43 ` k0kubun (Takashi Kokubun) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2024-05-29 22:43 UTC (permalink / raw
  To: ruby-core; +Cc: k0kubun (Takashi Kokubun)

Issue #20413 has been updated by k0kubun (Takashi Kokubun).

Backport changed from 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED to 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONE

ruby_3_3 commit:5688bcb54a640b353bed4ff49032ea00f947e1aa merged revision(s) commit:5d1702e01a36e11b183fe29ce10780a9b1a41cf0.

----------------------------------------
Bug #20413: Enumerator can block fiber scheduler.
https://bugs.ruby-lang.org/issues/20413#change-108501

* Author: ioquatix (Samuel Williams)
* Status: Closed
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONE
----------------------------------------
Using `Enumerator` in the event loop can cause problems as the fiber created by `rb_fiber_new` is blocking by default. It should be non-blocking.

```ruby
#!/usr/bin/env ruby

require 'async'

Async do
  Async do
    while true
      puts "Hello"
      sleep 1
    end
  end
  
  enumerator = Enumerator.new do |yielder|
    while true
      yielder << "World"
      sleep 1
    end
  end
  
  while true
    puts enumerator.next
  end
end
```

Before this PR, the output is:

```
> ./test.rb
Hello
World
World
World
World
World
World
...
```

After this PR, the output is:

```
> ./test.rb
Hello
World
Hello
World
Hello
World
Hello
World
Hello
World
...
```

The reason why this happens, is because the enumerator `sleep` never yields to the event loop.

See <https://github.com/ruby/ruby/pull/10481> for the fix.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-29 22:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-07 10:47 [ruby-core:117453] [Ruby master Bug#20413] Enumerator can block fiber scheduler ioquatix (Samuel Williams) via ruby-core
2024-04-07 11:16 ` [ruby-core:117454] " Eregon (Benoit Daloze) via ruby-core
2024-04-07 11:57 ` [ruby-core:117455] " ioquatix (Samuel Williams) via ruby-core
2024-04-07 12:48 ` [ruby-core:117456] " ioquatix (Samuel Williams) via ruby-core
2024-05-29 22:43 ` [ruby-core:118074] " k0kubun (Takashi Kokubun) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).