Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Marshal.dump(RBTree.new) #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kyrylo
Copy link

@kyrylo kyrylo commented Dec 12, 2018

I hit a bug with Marshal.dump(SortedSet.new) when rbtree is installed.

SortedSet uses RBTree when it's present:
https://github.com/ruby/ruby/blob/3a083985a471ca3d8429146f9f18dead6747c203/lib/set.rb#L710-L714

Because of that, any class that encapsulates a SortedSet is affected.

The bug happens because rb_marshal_dump doesn't accept limit as its second
argument:
https://github.com/ruby/ruby/blob/3a083985a471ca3d8429146f9f18dead6747c203/marshal.c#L2272

I'm no C Ruby API expert and I am not sure what port means but this change
does fix a failing test in this project.

I hit a bug with `Marshal.dump(SortedSet.new)` when `rbtree` is installed.

SortedSet uses RBTree when it's present:
https://github.com/ruby/ruby/blob/3a083985a471ca3d8429146f9f18dead6747c203/lib/set.rb#L710-L714

Because of that, any class that encapsulates a SortedSet is affected.

The bug happens because `rb_marshal_dump` doesn't accept `limit` as its second
argument:
https://github.com/ruby/ruby/blob/3a083985a471ca3d8429146f9f18dead6747c203/marshal.c#L2272

I'm no C Ruby API expert and I am not sure what `port` means but this change
does fix a failing test in this project.
kyrylo added a commit to kyrylo/rbtree3 that referenced this pull request Feb 7, 2019
I hit a bug with `Marshal.dump(SortedSet.new)` when `rbtree` is installed.

SortedSet uses RBTree when it's present:
https://github.com/ruby/ruby/blob/3a083985a471ca3d8429146f9f18dead6747c203/lib/set.rb#L710-L714

Because of that, any class that encapsulates a SortedSet is affected.

The bug happens because `rb_marshal_dump` doesn't accept `limit` as its second
argument:
https://github.com/ruby/ruby/blob/3a083985a471ca3d8429146f9f18dead6747c203/marshal.c#L2272

Ported from skade/rbtree#2
@kyrylo
Copy link
Author

kyrylo commented Feb 7, 2019

I ended up forking this repo and releasing a new version of the gem (gem name is rbtree3 but you still require 'rbtree': https://github.com/kyrylo/rbtree3

kyrylo added a commit to airbrake/airbrake-ruby that referenced this pull request Feb 7, 2019
A trail of events lead to this decision:

1. TDigest depends on unmaintained rbtree, which has a bug that our users
   complain about. An attempt to fix it was made but since the library is
   unmaintained, nobody merged it:
   skade/rbtree#2

2. We had to monkey-patch the TDigest library, so our backend understands
   tdigests. Since we import the library, we no longer need to monkey-patch
   anything: we can just fix the code itself to make it digestible for us.

3. The TDigest library itself is unmaintained. An attempt to reach original
   authors revaled that they're busy with other tasks:
   castle/tdigest#6

   TDigests are critical for our performance feature and we cannot afford
   neglecting the bug that haunts us in [1]. Luckily, the library is tiny (can
   fit into one file), and its licence (MIT) allows us to modify this code. Of
   course, to pay respect to the original author, a comment with a link is
   included into the comments

4. Thanks to all of this, I had a chance to fork rbtree and release it as
   rbtree3 (https://rubygems.org/gems/rbtree3). This RBTree is patched and
   should have no know bugs. Since we maintain TDigest now, we can directly
   depend on it (the TDigest gem depends on bugged rbtree)

5. Not the most important item in the list, but less dependencies means less
   headaches. That said, I would still perfer not to import anything but we need
   to move forward and unmaintained libraries slow us down
kyrylo added a commit to airbrake/airbrake-ruby that referenced this pull request Feb 7, 2019
A trail of events lead to this decision:

1. TDigest depends on unmaintained rbtree, which has a bug that our users
   complain about. An attempt to fix it was made but since the library is
   unmaintained, nobody merged it:
   skade/rbtree#2

2. We had to monkey-patch the TDigest library, so our backend understands
   tdigests. Since we import the library, we no longer need to monkey-patch
   anything: we can just fix the code itself to make it digestible for us.

3. The TDigest library itself is unmaintained. An attempt to reach original
   authors revaled that they're busy with other tasks:
   castle/tdigest#6

   TDigests are critical for our performance feature and we cannot afford
   neglecting the bug that haunts us in [1]. Luckily, the library is tiny (can
   fit into one file), and its licence (MIT) allows us to modify this code. Of
   course, to pay respect to the original author, a comment with a link is
   included into the comments

4. Thanks to all of this, I had a chance to fork rbtree and release it as
   rbtree3 (https://rubygems.org/gems/rbtree3). This RBTree is patched and
   should have no know bugs. Since we maintain TDigest now, we can directly
   depend on it (the TDigest gem depends on bugged rbtree)

5. Not the most important item in the list, but less dependencies means less
   headaches. That said, I would still perfer not to import anything but we need
   to move forward and unmaintained libraries slow us down
kyrylo added a commit to airbrake/airbrake-ruby that referenced this pull request Feb 7, 2019
A trail of events lead to this decision:

1. TDigest depends on unmaintained rbtree, which has a bug that our users
   complain about. An attempt to fix it was made but since the library is
   unmaintained, nobody merged it:
   skade/rbtree#2

2. We had to monkey-patch the TDigest library, so our backend understands
   tdigests. Since we import the library, we no longer need to monkey-patch
   anything: we can just fix the code itself to make it digestible for us.

3. The TDigest library itself is unmaintained. An attempt to reach original
   authors revaled that they're busy with other tasks:
   castle/tdigest#6

   TDigests are critical for our performance feature and we cannot afford
   neglecting the bug that haunts us in [1]. Luckily, the library is tiny (can
   fit into one file), and its licence (MIT) allows us to modify this code. Of
   course, to pay respect to the original author, a comment with a link is
   included into the comments

4. Thanks to all of this, I had a chance to fork rbtree and release it as
   rbtree3 (https://rubygems.org/gems/rbtree3). This RBTree is patched and
   should have no know bugs. Since we maintain TDigest now, we can directly
   depend on it (the TDigest gem depends on bugged rbtree)

5. Not the most important item in the list, but less dependencies means less
   headaches. That said, I would still perfer not to import anything but we need
   to move forward and unmaintained libraries slow us down
@skade
Copy link
Owner

skade commented Feb 11, 2019

@kyrylo Hi, sorry for the late reply. This is probably the best option, as this is not the authoritative repos and I have no access to the gem on rubygems.org. Sorry for missing this patch :).

@kyrylo
Copy link
Author

kyrylo commented Feb 11, 2019

No worries and thanks for the reply 👍

nevans pushed a commit to nevans/rbtree that referenced this pull request Nov 5, 2020
circle: make it run properly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants