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 bug with long stream identifiers when using Postgres adapter #29297
Fix bug with long stream identifiers when using Postgres adapter #29297
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @matthewd (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
77691d9
to
7094cd6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with SHA1 -- it shouldn't be user-controlled data, so I see no risk of collision. And it's used for network communication, so the extra time spent hashing should indeed be negligible.
It does seem a bit unfortunate to leave it totally opaque, though... is it worth keeping the first 22 characters?
@@ -32,7 +33,7 @@ def subscribe_as_queue(channel, adapter = @rx_adapter) | |||
subscribed.wait(WAIT_WHEN_EXPECTING_EVENT) | |||
assert subscribed.set? | |||
|
|||
yield queue | |||
Timeout.timeout(WAIT_WHEN_EXPECTING_EVENT) { yield queue } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, clarify?
That's an easiest way to handle blocking queue.pop
calls in these tests (which cause a process to stuck forever).
Of course, it would be better to refactor the tests to not use blocking calls though.
Another idea is to "enhance" Queue#pop
with built-in timeout through refinements:
refine Queue do
def pop(timeout)
while empty?
sleep 0.1
timeout -= 0.1
return nil unless timeout > 0
end
super
end
end
Or we can add custom queue class.
But either way, I think, we should be able to make tests fail (which is impossible now).
@@ -12,7 +12,7 @@ def setup | |||
if Dir.exist?(ar_tests) | |||
require File.join(ar_tests, "config") | |||
require File.join(ar_tests, "support/config") | |||
local_config = ARTest.config["arunit"] | |||
local_config = ARTest.config["connections"]["postgresql"]["arunit"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, we want to use the same DB configuration as in ActiveRecord tests (that's why we're using ARTest
).
ARTest.config["arunit"]
is always nil
, 'cause databases config has nested structure (connections -> adapter -> id).
I'm using custom PostgreSQL credentials in config.yml
, and it turned out that there is a bug here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be extracted into a separate PR, 'cause it does nothing with the bug under consideration.
Keeping in mind that we're working with long GlobalIDs, I'm not sure that would help, 'cause in that case the prefix would contain only a part of a namespace, e.g. "gid://app/MySuperModule/SubModule/Person/5" => "gid://app/MySuperModul". |
b2f6824
to
6efe6b5
Compare
6efe6b5
to
2bce777
Compare
@matthewd Codebase was cleaned up. Anything else I can do to get it merged? |
Sorry I didn't reply on this earlier. Beyond general concern about Timeout, allocating a single As for the ARTest thing -- yeah, I just couldn't work out why that was necessary for this change. If it's Just Wrong, we should definitely fix that. 🙈 |
If someone needs this backported to a released version of Rails the following will work:
I drop this in my |
Fixes #28751.
PostgreSQL has a limit on identifiers length (63 chars, docs).
Provided fix minifies identifiers longer than 63 chars by hashing them with SHA1.
Although it has an impact on performance, I think, it's negligible.
It would be great to use non-cryptographic hash functions (such as Murmur or CityHash), but that would require adding new dependencies.