-
Notifications
You must be signed in to change notification settings - Fork 439
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(PubSub): publisher compression type #6417
fix(PubSub): publisher compression type #6417
Conversation
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.
This is a bit worrisome because, while removing the typehint might get rid of the error, it's not the best way to fix this issue. Instead we should be looking at why these properties weren't initialized by the time they were accessed. They're being set properly in the constructor, so they should be initialized in every instance they're used.
My guess is that since we're using Sysv, there may be some strange behavior here. Those values aren't showing up on the other side when passed to the batch daemon.
When I switched the order so that the call to setCommonBatchProperties
happened after setting those properties, the error went away. I believe this is because when this method is called, it looks at what the initialized properties are, and only serializes those. So we need to initialize them beforehand.
I think this is a better solution, so please test and see if it works!
google-cloud-php/PubSub/src/BatchPublisher.php
Lines 90 to 96 in 5bf356c
$this->setCommonBatchProperties($options + [ | |
'identifier' => sprintf(self::ID_TEMPLATE, $topicName), | |
'batchMethod' => 'publishDeferred' | |
]); | |
$this->enableCompression = $options['enableCompression'] ?? false; | |
$this->compressionBytesThreshold = $options['compressionBytesThreshold'] ?? | |
Topic::DEFAULT_COMPRESSION_BYTES_THRESHOLD; |
(move lines 90-93 to be after line 96)
Thank you so much @bshaffer for zeroing this in🔥. I've raised a PR fixing this. #6423 |
Discussed internally offline that since the case when we do not use type checks eliminates the issue, hence we should go ahead with priortising the fixes until we properly figure out what exactly is causing this issue. |
Thanks for looking into this @bshaffer. We fixed your recommendation.
I am also not sure why not setting the properties in |
EDIT: I see now we already merged the other PR, so this comment is not necessary! As for the WHY this works - take this example: class ExampleFoo
{
protected string $typedVariable1;
protected string $typedVariable2;
protected $untypedVariable;
public function __construct()
{
// initialize one of the typed variables, but not the other
$this->typedVariable1 = 'initialized!';
}
public function getObjectVars()
{
return get_object_vars($this);
}
} In this example, we initialize one typed variable, but not the other. When we call $f = new ExampleFoo();
var_dump($f->getObjectVars());
// array(2) {
// ["typedVariable1"]=>
// string(12) "initialized!"
// ["untypedVariable"]=>
// NULL
//} This is a guess, I'd need to do more digging to be sure. |
Can you give me an example of this?
I found that strange as well - I wonder when they were added? I removed my review so feel free to merge it if you feel it's important! |
It seems it was complaining because of an older php version. When I test the following code in php7.3 or below it complains.
|
b/289990087