ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:115701] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations
@ 2023-12-11 21:18 zverok (Victor Shepelev) via ruby-core
  2023-12-11 21:42 ` [ruby-core:115702] " tenderlovemaking (Aaron Patterson) via ruby-core
  2023-12-12  0:05 ` [ruby-core:115711] " kyanagi (Kouhei Yanagita) via ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2023-12-11 21:18 UTC (permalink / raw
  To: ruby-core; +Cc: zverok (Victor Shepelev)

Issue #20059 has been reported by zverok (Victor Shepelev).

----------------------------------------
Bug #20059: TracePoint#enable can be called multiple times, increasing the number of invokations
https://bugs.ruby-lang.org/issues/20059

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I just stumbled upon this accidentally (created a tracepoint with `TracePoint.trace`, and then `enable`d it).

My initial example
```ruby
trace = TracePoint.trace(:raise) do |tp|
  puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
trace.enable # shouldn't do this, it was already enabled!
raise "foo"
```
This prints
```
Exception raised: #<RuntimeError: foo> at test.rb:5
Exception raised: #<RuntimeError: foo> at test.rb:5
```
Twice.
If I'll remove the "unnecessary" `trace.enable`, it prints it once.

So the theory is "multiple enables = multiple invokations of a tracepoint"...
```ruby
trace = TracePoint.trace(:raise) do |tp|
  puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
5.times { trace.enable }
raise "foo"
```
...and indeed, this code prints the "Exception raised:" message 6 times.

I don't see anything about this behavior in the [method's docs](https://docs.ruby-lang.org/en/master/TracePoint.html#method-i-enable) or class docs, and can't think of a plausible explanation. But it was this way since Ruby 2.0, and either it _should_ be this way, or it bothers nobody :)

I wonder:
* is there a reasonable explanation for this?
* if so, shouldn't it be documented somewhere?..

Or is it some part of a pattern of how the `TracePoint` works that I am missing here?..



-- 
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] 3+ messages in thread

* [ruby-core:115702] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations
  2023-12-11 21:18 [ruby-core:115701] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations zverok (Victor Shepelev) via ruby-core
@ 2023-12-11 21:42 ` tenderlovemaking (Aaron Patterson) via ruby-core
  2023-12-12  0:05 ` [ruby-core:115711] " kyanagi (Kouhei Yanagita) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: tenderlovemaking (Aaron Patterson) via ruby-core @ 2023-12-11 21:42 UTC (permalink / raw
  To: ruby-core; +Cc: tenderlovemaking (Aaron Patterson)

Issue #20059 has been updated by tenderlovemaking (Aaron Patterson).


IIRC the tracepoints are just added to a linked list. There's probably no validation as to whether or not that tracepoint has already been added to the linked list (and we just need to do that book keeping)

----------------------------------------
Bug #20059: TracePoint#enable can be called multiple times, increasing the number of invokations
https://bugs.ruby-lang.org/issues/20059#change-105633

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I just stumbled upon this accidentally (created a tracepoint with `TracePoint.trace`, and then `enable`d it).

My initial example
```ruby
trace = TracePoint.trace(:raise) do |tp|
  puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
trace.enable # shouldn't do this, it was already enabled!
raise "foo"
```
This prints
```
Exception raised: #<RuntimeError: foo> at test.rb:5
Exception raised: #<RuntimeError: foo> at test.rb:5
```
Twice.
If I'll remove the "unnecessary" `trace.enable`, it prints it once.

So the theory is "multiple enables = multiple invokations of a tracepoint"...
```ruby
trace = TracePoint.trace(:raise) do |tp|
  puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
5.times { trace.enable }
raise "foo"
```
...and indeed, this code prints the "Exception raised:" message 6 times.

I don't see anything about this behavior in the [method's docs](https://docs.ruby-lang.org/en/master/TracePoint.html#method-i-enable) or class docs, and can't think of a plausible explanation. But it was this way since Ruby 2.0, and either it _should_ be this way, or it bothers nobody :)

I wonder:
* is there a reasonable explanation for this?
* if so, shouldn't it be documented somewhere?..

Or is it some part of a pattern of how the `TracePoint` works that I am missing here?..



-- 
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] 3+ messages in thread

* [ruby-core:115711] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations
  2023-12-11 21:18 [ruby-core:115701] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations zverok (Victor Shepelev) via ruby-core
  2023-12-11 21:42 ` [ruby-core:115702] " tenderlovemaking (Aaron Patterson) via ruby-core
@ 2023-12-12  0:05 ` kyanagi (Kouhei Yanagita) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: kyanagi (Kouhei Yanagita) via ruby-core @ 2023-12-12  0:05 UTC (permalink / raw
  To: ruby-core; +Cc: kyanagi (Kouhei Yanagita)

Issue #20059 has been updated by kyanagi (Kouhei Yanagita).


Is this issue the same as #19114?
I have created a pull request for the fix at https://github.com/ruby/ruby/pull/8993.
Does this resolve the problem?

----------------------------------------
Bug #20059: TracePoint#enable can be called multiple times, increasing the number of invokations
https://bugs.ruby-lang.org/issues/20059#change-105641

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I just stumbled upon this accidentally (created a tracepoint with `TracePoint.trace`, and then `enable`d it).

My initial example
```ruby
trace = TracePoint.trace(:raise) do |tp|
  puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
trace.enable # shouldn't do this, it was already enabled!
raise "foo"
```
This prints
```
Exception raised: #<RuntimeError: foo> at test.rb:5
Exception raised: #<RuntimeError: foo> at test.rb:5
```
Twice.
If I'll remove the "unnecessary" `trace.enable`, it prints it once.

So the theory is "multiple enables = multiple invokations of a tracepoint"...
```ruby
trace = TracePoint.trace(:raise) do |tp|
  puts "Exception raised: #{tp.raised_exception.inspect} at #{tp.path}:#{tp.lineno}"
end
5.times { trace.enable }
raise "foo"
```
...and indeed, this code prints the "Exception raised:" message 6 times.

I don't see anything about this behavior in the [method's docs](https://docs.ruby-lang.org/en/master/TracePoint.html#method-i-enable) or class docs, and can't think of a plausible explanation. But it was this way since Ruby 2.0, and either it _should_ be this way, or it bothers nobody :)

I wonder:
* is there a reasonable explanation for this?
* if so, shouldn't it be documented somewhere?..

Or is it some part of a pattern of how the `TracePoint` works that I am missing here?..



-- 
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] 3+ messages in thread

end of thread, other threads:[~2023-12-12  0:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-11 21:18 [ruby-core:115701] [Ruby master Bug#20059] TracePoint#enable can be called multiple times, increasing the number of invokations zverok (Victor Shepelev) via ruby-core
2023-12-11 21:42 ` [ruby-core:115702] " tenderlovemaking (Aaron Patterson) via ruby-core
2023-12-12  0:05 ` [ruby-core:115711] " kyanagi (Kouhei Yanagita) 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).