ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout
@ 2024-01-30 19:29 peterzhu2118 (Peter Zhu) via ruby-core
  2024-01-31  0:57 ` [ruby-core:116520] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: peterzhu2118 (Peter Zhu) via ruby-core @ 2024-01-30 19:29 UTC (permalink / raw)
  To: ruby-core; +Cc: peterzhu2118 (Peter Zhu)

Issue #20228 has been reported by peterzhu2118 (Peter Zhu).

----------------------------------------
Bug #20228: Memory leak in Regexp timeout
https://bugs.ruby-lang.org/issues/20228

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the `stk_base` and `OnigRegion` will leak.

For example:

```ruby
Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664
```

After:

```
39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
```



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

* [ruby-core:116520] [Ruby master Bug#20228] Memory leak in Regexp timeout
  2024-01-30 19:29 [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout peterzhu2118 (Peter Zhu) via ruby-core
@ 2024-01-31  0:57 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-01-31  4:12 ` [ruby-core:116522] " mame (Yusuke Endoh) via ruby-core
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-01-31  0:57 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20228 has been updated by nobu (Nobuyoshi Nakada).


Using ruby APIs in onigmo doesn’t feel nice.

----------------------------------------
Bug #20228: Memory leak in Regexp timeout
https://bugs.ruby-lang.org/issues/20228#change-106539

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the `stk_base` and `OnigRegion` will leak.

For example:

```ruby
Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664
```

After:

```
39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
```



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

* [ruby-core:116522] [Ruby master Bug#20228] Memory leak in Regexp timeout
  2024-01-30 19:29 [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout peterzhu2118 (Peter Zhu) via ruby-core
  2024-01-31  0:57 ` [ruby-core:116520] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-01-31  4:12 ` mame (Yusuke Endoh) via ruby-core
  2024-01-31 16:30 ` [ruby-core:116526] " peterzhu2118 (Peter Zhu) via ruby-core
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-01-31  4:12 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

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


Good find, thanks!

I'm a little concerned about the overhead of `rb_protect` for a typical simple match, but it's neglectable?

----------------------------------------
Bug #20228: Memory leak in Regexp timeout
https://bugs.ruby-lang.org/issues/20228#change-106541

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the `stk_base` and `OnigRegion` will leak.

For example:

```ruby
Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664
```

After:

```
39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
```



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

* [ruby-core:116526] [Ruby master Bug#20228] Memory leak in Regexp timeout
  2024-01-30 19:29 [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout peterzhu2118 (Peter Zhu) via ruby-core
  2024-01-31  0:57 ` [ruby-core:116520] " nobu (Nobuyoshi Nakada) via ruby-core
  2024-01-31  4:12 ` [ruby-core:116522] " mame (Yusuke Endoh) via ruby-core
@ 2024-01-31 16:30 ` peterzhu2118 (Peter Zhu) via ruby-core
  2024-03-20 16:34 ` [ruby-core:117265] " naruse (Yui NARUSE) via ruby-core
  2024-07-07  5:24 ` [ruby-core:118470] " nagachika (Tomoyuki Chikanaga) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: peterzhu2118 (Peter Zhu) via ruby-core @ 2024-01-31 16:30 UTC (permalink / raw)
  To: ruby-core; +Cc: peterzhu2118 (Peter Zhu)

Issue #20228 has been updated by peterzhu2118 (Peter Zhu).


> Using ruby APIs in onigmo doesn’t feel nice.

I changed it to call `HANDLE_REG_TIMEOUT_IN_MATCH_AT` in onigmo, which calls `rb_reg_raise_timeout` so then there is no Ruby code in onigmo.

> I'm a little concerned about the overhead of rb_protect for a typical simple match, but it's neglectable?

I think it can only raise when there is a timeout set, so I changed the implementation to only use `rb_protect` when there is a timeout.

----------------------------------------
Bug #20228: Memory leak in Regexp timeout
https://bugs.ruby-lang.org/issues/20228#change-106544

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: REQUIRED
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the `stk_base` and `OnigRegion` will leak.

For example:

```ruby
Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664
```

After:

```
39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
```



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

* [ruby-core:117265] [Ruby master Bug#20228] Memory leak in Regexp timeout
  2024-01-30 19:29 [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout peterzhu2118 (Peter Zhu) via ruby-core
                   ` (2 preceding siblings ...)
  2024-01-31 16:30 ` [ruby-core:116526] " peterzhu2118 (Peter Zhu) via ruby-core
@ 2024-03-20 16:34 ` naruse (Yui NARUSE) via ruby-core
  2024-07-07  5:24 ` [ruby-core:118470] " nagachika (Tomoyuki Chikanaga) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: naruse (Yui NARUSE) via ruby-core @ 2024-03-20 16:34 UTC (permalink / raw)
  To: ruby-core; +Cc: naruse (Yui NARUSE)

Issue #20228 has been updated by naruse (Yui NARUSE).

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

ruby_3_3 c626c201e4129bbea17583ecef73472c6f668c81 merged revision(s) 01bfd1a2bf013a9ed92a9722ac5228187e05e6a8,1c120efe02d079b0a1dea573cf0fd7978d9cc857,31378dc0969f4466b2122d730b7298dd7004acdf.

----------------------------------------
Bug #20228: Memory leak in Regexp timeout
https://bugs.ruby-lang.org/issues/20228#change-107359

* Author: peterzhu2118 (Peter Zhu)
* Status: Closed
* Backport: 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: REQUIRED, 3.3: DONE
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the `stk_base` and `OnigRegion` will leak.

For example:

```ruby
Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664
```

After:

```
39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
```



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

* [ruby-core:118470] [Ruby master Bug#20228] Memory leak in Regexp timeout
  2024-01-30 19:29 [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout peterzhu2118 (Peter Zhu) via ruby-core
                   ` (3 preceding siblings ...)
  2024-03-20 16:34 ` [ruby-core:117265] " naruse (Yui NARUSE) via ruby-core
@ 2024-07-07  5:24 ` nagachika (Tomoyuki Chikanaga) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: nagachika (Tomoyuki Chikanaga) via ruby-core @ 2024-07-07  5:24 UTC (permalink / raw)
  To: ruby-core; +Cc: nagachika (Tomoyuki Chikanaga)

Issue #20228 has been updated by nagachika (Tomoyuki Chikanaga).

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

I gave up to make a clean patch for ruby_3_2 branch. Please make PR if you want to backport.

----------------------------------------
Bug #20228: Memory leak in Regexp timeout
https://bugs.ruby-lang.org/issues/20228#change-108984

* Author: peterzhu2118 (Peter Zhu)
* Status: Closed
* Backport: 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: WONTFIX, 3.3: DONE
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the `stk_base` and `OnigRegion` will leak.

For example:

```ruby
Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end
```

Before:

```
328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664
```

After:

```
39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
```



-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2024-07-07  5:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 19:29 [ruby-core:116514] [Ruby master Bug#20228] Memory leak in Regexp timeout peterzhu2118 (Peter Zhu) via ruby-core
2024-01-31  0:57 ` [ruby-core:116520] " nobu (Nobuyoshi Nakada) via ruby-core
2024-01-31  4:12 ` [ruby-core:116522] " mame (Yusuke Endoh) via ruby-core
2024-01-31 16:30 ` [ruby-core:116526] " peterzhu2118 (Peter Zhu) via ruby-core
2024-03-20 16:34 ` [ruby-core:117265] " naruse (Yui NARUSE) via ruby-core
2024-07-07  5:24 ` [ruby-core:118470] " nagachika (Tomoyuki Chikanaga) 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 NNTP newsgroup(s).