ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
@ 2020-09-03 22:53 eregontp
  2020-09-04  0:58 ` [ruby-core:99908] " ko1
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: eregontp @ 2020-09-03 22:53 UTC (permalink / raw)
  To: ruby-core

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

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

* 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/

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

* [ruby-core:99908] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
@ 2020-09-04  0:58 ` ko1
  2020-09-04  1:52 ` [ruby-core:99911] " merch-redmine
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ko1 @ 2020-09-04  0:58 UTC (permalink / raw)
  To: ruby-core

Issue #17146 has been updated by ko1 (Koichi Sasada).


> I guess old Thread::Queue implemented in Ruby did not have this bug.


`require "thread"; q=Queue.new.freeze; q.push 1` works without error from Ruby 1.6.0.
Surprisingly before 1.6.0 there is no `Queue#freeze`.

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

* 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/

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

* [ruby-core:99911] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
  2020-09-04  0:58 ` [ruby-core:99908] " ko1
@ 2020-09-04  1:52 ` merch-redmine
  2020-09-04  3:56 ` [ruby-core:99913] " ko1
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: merch-redmine @ 2020-09-04  1:52 UTC (permalink / raw)
  To: ruby-core

Issue #17146 has been updated by jeremyevans0 (Jeremy Evans).


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.

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.

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

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

* 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/

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

* [ruby-core:99913] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
  2020-09-04  0:58 ` [ruby-core:99908] " ko1
  2020-09-04  1:52 ` [ruby-core:99911] " merch-redmine
@ 2020-09-04  3:56 ` ko1
  2020-09-13  9:25 ` [ruby-core:99999] " eregontp
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ko1 @ 2020-09-04  3:56 UTC (permalink / raw)
  To: ruby-core

Issue #17146 has been updated by ko1 (Koichi Sasada).


It seems "what is freeze mean" discussion.

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

* 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/

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

* [ruby-core:99999] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (2 preceding siblings ...)
  2020-09-04  3:56 ` [ruby-core:99913] " ko1
@ 2020-09-13  9:25 ` eregontp
  2020-10-26 16:42 ` [ruby-core:100587] " ko1
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: eregontp @ 2020-09-13  9:25 UTC (permalink / raw)
  To: ruby-core

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/

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

* [ruby-core:100587] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (3 preceding siblings ...)
  2020-09-13  9:25 ` [ruby-core:99999] " eregontp
@ 2020-10-26 16:42 ` ko1
  2021-10-20 14:23 ` [ruby-core:105695] " Eregon (Benoit Daloze)
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ko1 @ 2020-10-26 16:42 UTC (permalink / raw)
  To: ruby-core

Issue #17146 has been updated by ko1 (Koichi Sasada).

Status changed from Open to Feedback

At last dev-meeting we skipped this issue because it is difficult, but no benefit to change the current behavior.

BTW

> AFAIK no other class undefines #freeze, that seems unfriendly.

`ENV.freeze` raises an error (`freeze': cannot freeze ENV (TypeError)).

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

* Author: Eregon (Benoit Daloze)
* Status: Feedback
* 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/

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

* [ruby-core:105695] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (4 preceding siblings ...)
  2020-10-26 16:42 ` [ruby-core:100587] " ko1
@ 2021-10-20 14:23 ` Eregon (Benoit Daloze)
  2021-10-20 14:44 ` [ruby-core:105698] " jeremyevans0 (Jeremy Evans)
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2021-10-20 14:23 UTC (permalink / raw)
  To: ruby-core

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

Status changed from Closed to Open

Why was this closed?

I think there is only one rational answer here:
`Queue#freeze` should prevent mutations to the Queue just like for Array/Hash/etc.

There is no other "nested object" (i.e., the queue contents) exposed to user code, so it would just be weird if `Queue#deep_freeze` would actually prevent mutation of the queue but `Queue#freeze` does not.

"deep freeze" should be equivalent to calling `freeze` on each object in an object graph, this can't work if `Queue#freeze` doesn't prevent mutations.

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

* 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/

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

* [ruby-core:105698] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (5 preceding siblings ...)
  2021-10-20 14:23 ` [ruby-core:105695] " Eregon (Benoit Daloze)
@ 2021-10-20 14:44 ` jeremyevans0 (Jeremy Evans)
  2021-10-20 15:53 ` [ruby-core:105699] " Eregon (Benoit Daloze)
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2021-10-20 14:44 UTC (permalink / raw)
  To: ruby-core

Issue #17146 has been updated by jeremyevans0 (Jeremy Evans).


Eregon (Benoit Daloze) wrote in #note-7:
> Why was this closed?

Because there was no feedback after the last message from @ko1, and it was decided at the developer meeting last year that there was no benefit to changing the behavior.

You are welcome to bring this issue up again at another developer meeting.  However, if the same conclusion is reached, I think this issue should be closed again.

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

* 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/

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

* [ruby-core:105699] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (6 preceding siblings ...)
  2021-10-20 14:44 ` [ruby-core:105698] " jeremyevans0 (Jeremy Evans)
@ 2021-10-20 15:53 ` Eregon (Benoit Daloze)
  2021-10-20 15:56 ` [ruby-core:105700] " Eregon (Benoit Daloze)
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2021-10-20 15:53 UTC (permalink / raw)
  To: ruby-core

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


OK, that `no benefit to changing the behavior.` was not reported here but I guess it's in the dev meeting log.

Benefit is consistency and being able to design deep freezing/immutable without making an exception for Queue.
Every time deep freezing/immutable comes up, this comes up as well as a problem.

I argue the current behavior is useful to nobody, and it's highly inconsistent, i.e., let's fix it.

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

* 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/

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

* [ruby-core:105700] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (7 preceding siblings ...)
  2021-10-20 15:53 ` [ruby-core:105699] " Eregon (Benoit Daloze)
@ 2021-10-20 15:56 ` Eregon (Benoit Daloze)
  2021-10-20 16:17 ` [ruby-core:105702] " jeremyevans0 (Jeremy Evans)
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2021-10-20 15:56 UTC (permalink / raw)
  To: ruby-core

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


(an alternative would be to have some other way to freeze the Queue for the purpose of `deep_freeze`/`Immutable`, but I see no value to that, the way is called `freeze` and it already works for most objects).

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

* 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/

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

* [ruby-core:105702] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (8 preceding siblings ...)
  2021-10-20 15:56 ` [ruby-core:105700] " Eregon (Benoit Daloze)
@ 2021-10-20 16:17 ` jeremyevans0 (Jeremy Evans)
  2021-10-20 17:58 ` [ruby-core:105704] " Eregon (Benoit Daloze)
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2021-10-20 16:17 UTC (permalink / raw)
  To: ruby-core

Issue #17146 has been updated by jeremyevans0 (Jeremy Evans).


Eregon (Benoit Daloze) wrote in #note-9:
> OK, that `no benefit to changing the behavior.` was not reported here but I guess it's in the dev meeting log.

ko1 (Koichi Sasada) wrote in #note-5:
> At last dev-meeting we skipped this issue because it is difficult, but no benefit to change the current behavior.


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

* 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/

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

* [ruby-core:105704] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (9 preceding siblings ...)
  2021-10-20 16:17 ` [ruby-core:105702] " jeremyevans0 (Jeremy Evans)
@ 2021-10-20 17:58 ` Eregon (Benoit Daloze)
  2021-10-20 20:32 ` [ruby-core:105705] " ioquatix (Samuel Williams)
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: Eregon (Benoit Daloze) @ 2021-10-20 17:58 UTC (permalink / raw)
  To: ruby-core

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


Indeed, sorry, I missed that somehow.

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

* 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/

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

* [ruby-core:105705] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (10 preceding siblings ...)
  2021-10-20 17:58 ` [ruby-core:105704] " Eregon (Benoit Daloze)
@ 2021-10-20 20:32 ` ioquatix (Samuel Williams)
  2023-09-14  5:37 ` [ruby-core:114739] " matz (Yukihiro Matsumoto) via ruby-core
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: ioquatix (Samuel Williams) @ 2021-10-20 20:32 UTC (permalink / raw)
  To: ruby-core

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


> I think there is only one rational answer here: Queue#freeze should prevent mutations to the Queue just like for Array/Hash/etc.

I agree with this for consistency reasons. Anyone who is freezing a queue and expecting it to work has buggy code.

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

* 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/

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

* [ruby-core:114739] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (11 preceding siblings ...)
  2021-10-20 20:32 ` [ruby-core:105705] " ioquatix (Samuel Williams)
@ 2023-09-14  5:37 ` matz (Yukihiro Matsumoto) via ruby-core
  2023-09-14 13:36 ` [ruby-core:114751] " mame (Yusuke Endoh) via ruby-core
  2023-09-27  0:21 ` [ruby-core:114900] " jeremyevans0 (Jeremy Evans) via ruby-core
  14 siblings, 0 replies; 16+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2023-09-14  5:37 UTC (permalink / raw)
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

Issue #17146 has been updated by matz (Yukihiro Matsumoto).


Since frozen `queue` is meaningless, if you care about consistency, we should prohibit `freeze` queues, like `ENV`.

Matz.


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

* 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/
 ______________________________________________
 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] 16+ messages in thread

* [ruby-core:114751] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (12 preceding siblings ...)
  2023-09-14  5:37 ` [ruby-core:114739] " matz (Yukihiro Matsumoto) via ruby-core
@ 2023-09-14 13:36 ` mame (Yusuke Endoh) via ruby-core
  2023-09-27  0:21 ` [ruby-core:114900] " jeremyevans0 (Jeremy Evans) via ruby-core
  14 siblings, 0 replies; 16+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2023-09-14 13:36 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #17146 has been updated by mame (Yusuke Endoh).


I would like to add a point that came up during the dev meeting: if a thread is waiting for `Queue#pop`, and another thread freezes the Queue, what should the first thread do? Wait forever? Raise a FrozenError?

To raise a FrozenError, it needs to be told that the Queue was asynchronously frozen by another thread. In other words, `Queue#freeze` needs to wake up the thread waiting for the Queue, which is likely to do more than `#freeze` would normally be expected to do.



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

* 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/
 ______________________________________________
 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] 16+ messages in thread

* [ruby-core:114900] [Ruby master Bug#17146] Queue operations are allowed after it is frozen
  2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
                   ` (13 preceding siblings ...)
  2023-09-14 13:36 ` [ruby-core:114751] " mame (Yusuke Endoh) via ruby-core
@ 2023-09-27  0:21 ` jeremyevans0 (Jeremy Evans) via ruby-core
  14 siblings, 0 replies; 16+ messages in thread
From: jeremyevans0 (Jeremy Evans) via ruby-core @ 2023-09-27  0:21 UTC (permalink / raw)
  To: ruby-core; +Cc: jeremyevans0 (Jeremy Evans)

Issue #17146 has been updated by jeremyevans0 (Jeremy Evans).


I submitted a pull request to have `{Queue,SizedQueue}#freeze` raise `TypeError`, as `ENV.freeze` does: https://github.com/ruby/ruby/pull/8515

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

* 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/
 ______________________________________________
 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] 16+ messages in thread

end of thread, other threads:[~2023-09-27  0:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 22:53 [ruby-core:99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen eregontp
2020-09-04  0:58 ` [ruby-core:99908] " ko1
2020-09-04  1:52 ` [ruby-core:99911] " merch-redmine
2020-09-04  3:56 ` [ruby-core:99913] " ko1
2020-09-13  9:25 ` [ruby-core:99999] " eregontp
2020-10-26 16:42 ` [ruby-core:100587] " ko1
2021-10-20 14:23 ` [ruby-core:105695] " Eregon (Benoit Daloze)
2021-10-20 14:44 ` [ruby-core:105698] " jeremyevans0 (Jeremy Evans)
2021-10-20 15:53 ` [ruby-core:105699] " Eregon (Benoit Daloze)
2021-10-20 15:56 ` [ruby-core:105700] " Eregon (Benoit Daloze)
2021-10-20 16:17 ` [ruby-core:105702] " jeremyevans0 (Jeremy Evans)
2021-10-20 17:58 ` [ruby-core:105704] " Eregon (Benoit Daloze)
2021-10-20 20:32 ` [ruby-core:105705] " ioquatix (Samuel Williams)
2023-09-14  5:37 ` [ruby-core:114739] " matz (Yukihiro Matsumoto) via ruby-core
2023-09-14 13:36 ` [ruby-core:114751] " mame (Yusuke Endoh) via ruby-core
2023-09-27  0:21 ` [ruby-core:114900] " jeremyevans0 (Jeremy Evans) 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).