Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Lock] MongoDbStore skim non-standard options from uri#37218

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.1fromkralos:37180-lock-mongodbstore-uri
Aug 16, 2020

Conversation

@kralos
Copy link

QA
Branch?5.1
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#37180
LicenseMIT
Doc PR

Don't allow non-standard connection uri options reachMongoDB\Client

@kraloskralos changed the base branch frommaster to5.1June 11, 2020 13:19
parse_str($parsedUrl['query'],$query);
}

if (null === ($this->options['collection'] ??null) &&isset($query['collection'])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know this was already the case before your PR, but the precedence looks wrong to me:
the DSN should have higher precedence over options (I just double-checked, that's how the Cache component does also).

/cc@jderusse maybe we should review all DSN parsing logic to ensure the precedence is consistent everywhere
/cc@Nyholm that's a good case forthe DSN component - formalizing this behavior :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍 not only in cache and lock.

messenger Doctrine:

$configuration +=$options +$query +static::DEFAULT_OPTIONS;

messenger Redis:

parse_str($parsedUrl['query'],$options);

messenger Sqs

$configuration = ['buffer_size'] =$options['buffer_size'] ?? (int) ($query['buffer_size'] ??self::DEFAULT_OPTIONS['buffer_size']),

messenger amqp

$amqpOptions =array_replace_recursive([],$options,$parsedQuery);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Bad news, we need to fix this. Up for a PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@nicolas-grekas In order to change the precedence, I think we should detectdsn /options where a precedence change would cause an effective option change and insteadtrigger_deprecation for now. Then swap the precedence insymfony6.0. Do you want me to add this detection /trigger_deprecation in this PR forLock\Store\MongoDbStore only or should we make a list of ALLdsn /options precedence affected classes and do them in a separate PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've added the precedence change since you guys seem to be classing this as a bug rather than a deprecation in:#37268

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There is no way to deprecate this behavior properly. Also this will very unlikely hit anyone. This precedence issue lessens the capabilities of the ops side of things. Basically, having the options take over the DSN means that the source needs to change (the options) instead of some env vars. That's a management issue at this point, and this change fixes a process issue: the env vars should always win to give control to the ops, which are the ones that know better since they're the ones in touch with the effective infra.

TL;DR, this is a bugfix.

@kraloskralos marked this pull request as ready for reviewJune 15, 2020 06:05
@kraloskralos requested a review fromxabbuh as acode ownerJune 15, 2020 06:24
@kraloskralosforce-pushed the37180-lock-mongodbstore-uri branch 2 times, most recently frome06956a to599c128CompareJune 15, 2020 06:48
@nicolas-grekasnicolas-grekas added this to the5.1 milestoneJun 18, 2020
nicolas-grekas added a commit that referenced this pull requestJun 18, 2020
…derusse)This PR was squashed before being merged into the 5.1 branch.Discussion----------[Lock][Messenger] Fix precedence of DSN options for 5.1| Q             | A| ------------- | ---| Branch?       | 5.1| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |#37218 (comment)| License       | MIT| Doc PR        | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 5.1Commits-------9670e9f [Lock][Messenger] Fix precedence of DSN options for 5.1
nicolas-grekas added a commit that referenced this pull requestJun 18, 2020
This PR was merged into the 4.4 branch.Discussion----------[Messenger] Fix precedence of DSN options for 4.4| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |#37218 (comment)| License       | MIT| Doc PR        | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 4.4Commits-------992205a Fix precendence in 4.4
symfony-splitter pushed a commit to symfony/messenger that referenced this pull requestJun 18, 2020
This PR was merged into the 4.4 branch.Discussion----------[Messenger] Fix precedence of DSN options for 4.4| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |symfony/symfony#37218 (comment)| License       | MIT| Doc PR        | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 4.4Commits-------992205a759 Fix precendence in 4.4
@nicolas-grekas
Copy link
Member

Can you please rebase now that the priority is fixed?

@kraloskralos marked this pull request as draftJune 18, 2020 23:08
@kraloskralosforce-pushed the37180-lock-mongodbstore-uri branch from4df26a9 to523bf2aCompareJune 18, 2020 23:08
@kraloskralos marked this pull request as ready for reviewJune 18, 2020 23:17
privatefunctionskimUri(string$uri):string
{
if (false ===$parsedUrl =parse_url($uri)) {
thrownewInvalidArgumentException(sprintf('The given MongoDB Connection URI "%s" is invalid.',$mongo));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

$mongo is not defined

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

/**
* Extract default database and collection from given connection uri and remove collection querystring.
*/
privatefunctionskimUri(string$uri):string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not comfortable with this method, a lot of complex logic to extract parameter from URI mixing parse_str and strpos.

Givent the format of the initialDSN is defined by symfony, wouldn't it be safer to build the mongo URI instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the reason i chose to use strpos to re-assemble was to simplify the re-assembly. there is no reverse of parse_str in php. seehttps://www.php.net/manual/en/function.parse-url.php#106731

I'm trying not to get too involved with touching the URI. What would you suggest that is simpler?

@jderusse
Copy link
Member

@nicolas-grekas LGTM from a lock point of view. I just have concerns about complexity of url generator#37218 (comment) . If you think it's ok you can merge it.

@fabpotfabpotforce-pushed the37180-lock-mongodbstore-uri branch from79fee70 to67912faCompareAugust 16, 2020 14:54
@fabpot
Copy link
Member

Thank you@kralos.

jmikola reacted with thumbs up emoji

@fabpotfabpot merged commit5f074cd intosymfony:5.1Aug 16, 2020
$prefix =rtrim($prefix,'?');
}
$suffix =substr($uri,$queryStringPos +\strlen($parsedUrl['query']));
$uri =$prefix.$newQuery.$suffix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@kralos: I only just came across this PR based on a notification in#37180. I understand what this function is attempting to do, but usingparse_str may silently corrupting a connection string with repeatedreadPreferenceTags keys (a valid use case, as explained in theURI options spec).This comment on PHP.net goes into more detail about that.

I think it would be preferable to capture the URI option with a regular expression and then, if anything was found, strip it from the returned string. While collection names have theirown restrictions, for purposes of URI parsing I think it'd be best to use something like/collection=([^&]*)/i.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@kraloskralos deleted the 37180-lock-mongodbstore-uri branchAugust 17, 2020 23:40
@fabpotfabpot mentioned this pull requestAug 31, 2020
symfony-splitter pushed a commit to symfony/messenger that referenced this pull requestSep 28, 2021
This PR was merged into the 4.4 branch.Discussion----------[Messenger] Fix precedence of DSN options for 4.4| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |symfony/symfony#37218 (comment)| License       | MIT| Doc PR        | N/AThis PR fix précédence of DSN options over constructor options in all component on branch 4.4Commits-------992205a759 Fix precendence in 4.4
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@xabbuhxabbuhAwaiting requested review from xabbuh

@nicolas-grekasnicolas-grekasAwaiting requested review from nicolas-grekas

@jderussejderusseAwaiting requested review from jderussejderusse is a code owner

+1 more reviewer

@jmikolajmikolajmikola left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.1

Development

Successfully merging this pull request may close these issues.

[Lock] remove non-standard MongoDbStore URI parameters before passing to driver

6 participants

@kralos@nicolas-grekas@jderusse@fabpot@jmikola@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp