[#99856] [Ruby master Feature#17143] Improve support for warning categories — merch-redmine@...

Issue #17143 has been reported by jeremyevans0 (Jeremy Evans).

16 messages 2020/09/03

[#99868] [Ruby master Bug#17144] Tempfile.open { ... } does not unlink the file — eregontp@...

Issue #17144 has been reported by Eregon (Benoit Daloze).

15 messages 2020/09/03

[#99885] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze` — marcandre-ruby-core@...

Issue #17145 has been reported by marcandre (Marc-Andre Lafortune).

32 messages 2020/09/03

[#99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen — eregontp@...

Issue #17146 has been reported by Eregon (Benoit Daloze).

16 messages 2020/09/03

[#100016] [Ruby master Feature#17171] Why is the visibility of constants not affected by `private`? — marcandre-ruby-core@...

Issue #17171 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/09/15

[#100024] [Ruby master Bug#17175] Ruby 2.5: OpenSSL related test failures — jaruga@...

Issue #17175 has been reported by jaruga (Jun Aruga).

10 messages 2020/09/16

[#100025] [Ruby master Feature#17176] GC.enable_autocompact / GC.disable_autocompact — tenderlove@...

Issue #17176 has been reported by tenderlovemaking (Aaron Patterson).

11 messages 2020/09/16

[#100099] [Ruby master Bug#17184] No stdlib function to perform simple string replacement — sheerun@...

Issue #17184 has been reported by sheerun (Adam Stankiewicz).

18 messages 2020/09/24

[#100192] [Ruby master Bug#17197] Some Hash methods still have arity 2 instead of 1 — marcandre-ruby-core@...

Issue #17197 has been reported by marcandre (Marc-Andre Lafortune).

14 messages 2020/09/28

[#100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa — baptiste.courtois@...

Issue #17199 has been reported by Annih (Baptiste Courtois).

7 messages 2020/09/28

[#100206] [Ruby master Misc#17200] DevelopersMeeting20201026Japan — mame@...

Issue #17200 has been reported by mame (Yusuke Endoh).

18 messages 2020/09/28

[#100239] [Ruby master Feature#17206] Introduce new Regexp option to avoid MatchData allocation — fatkodima123@...

Issue #17206 has been reported by fatkodima (Dima Fatko).

8 messages 2020/09/30

[ruby-core:99999] [Ruby master Bug#17146] Queue operations are allowed after it is frozen

From: eregontp@...
Date: 2020-09-13 09:25:32 UTC
List: ruby-core #99999
Issue #17146 has been updated by Eregon (Benoit Daloze).


ko1 (Koichi Sasada) wrote in #note-1:
> `require "thread"; q=Queue.new.freeze; q.push 1` works without error from Ruby 1.6.0.

Ah, yes, because it's not deeply frozen:
https://github.com/ruby/ruby/blob/23ccbdf52188b78427f41d75b1a4b81959ac9876/lib/thread.rb#L145

At least #deep_freeze on Queue should prevent #push/#pop.
But I think #freeze should prevent #push/#pop too, just like for every other core collection.

jeremyevans0 (Jeremy Evans) wrote in #note-2:
> If a Queue cannot push/pop, it is useless.  A Queue doesn't have any operations on that would make sense if you cannot push/pop.  This makes it  different from most freezable objects, where the object is usable read-only in a frozen state.

One could still use Queue#empty? and Queue#size.
I think freezing a Queue should be similar to Queue#close, but also prevent #pop.
Many objects become severely limited when deeply frozen. I don't think Queue should be a special case.

> In relation to Ractor/deep_freeze discussion, if deep_freeze is called on an object that contains a Queue (directly or transitively), and Queue#freeze makes the Queue unusable, it seems very dangerous.  It would be best if Queue was an shareable object whose operations worked across Ractors.  For example, assuming the object was sharable, a push of the object onto the Queue on Ractor A, while Ractor B, C, and D were waiting in Queue#pop, would result in only one of B, C, D popping the object. However, I don't know whether or not that is feasible.

What if it's a non-shareable object?
It seems unacceptable to copy the object in that case, because how would we know if it is the same or different Ractor that will Queue#pop that element?

So IMHO the simplest thing makes sense: Queue#freeze prevents modifications to the Queue (which is the general contract of #freeze for collections). A Queue cannot be copied by Ractor (neither by #dup nor Marshal.dump). The Queue can be frozen but then indeed is of limited value.

Ractor communicate via their internal channels.
Queues don't work with Ractor (i.e., cannot be used to communicate between Ractors), and they cannot for compatibility (would copy non-shareable elements, which would be incompatible).

> I think the best solution for `Queue#freeze` is `Queue.send(:undef_method, :freeze)`.

AFAIK no other class undefines #freeze, that seems unfriendly.
I don't see any real-world motivation to prevent freezing a Queue (and it would be inconsistent).
So I think this is a plain bug and we should fix it.

----------------------------------------
Bug #17146: Queue operations are allowed after it is frozen
https://bugs.ruby-lang.org/issues/17146#change-87546

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
```
[1] pry(main)> q = Queue.new
=> #<Thread::Queue:0x000056263683aee8>
[2] pry(main)> q.freeze
=> #<Thread::Queue:0x000056263683aee8>
[3] pry(main)> q << 1
=> #<Thread::Queue:0x000056263683aee8>
[4] pry(main)> q.pop
=> 1
[5] pry(main)> q.frozen?
=> true
```

Found by @ko1 in https://bugs.ruby-lang.org/issues/17100#note-28

I think it's a bug, since those are clear mutations.
I guess old Thread::Queue implemented in Ruby did not have this bug.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread