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

Fix for race condition in console output stream write#28813

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
nicolas-grekas merged 1 commit intosymfony:2.8fromrudolfratusinski:2.8
Oct 14, 2018
Merged

Fix for race condition in console output stream write#28813

nicolas-grekas merged 1 commit intosymfony:2.8fromrudolfratusinski:2.8
Oct 14, 2018

Conversation

@rudolfratusinski
Copy link
Contributor

QA
Branch?2.8
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

In high throughput environments writingmessage andPHP_EOL separately causes race condition issues, where messages might be written in order

  • message
  • message
  • EOL
  • EOL

instead of

  • message
  • EOL
  • message
  • EOL

An example below is a laravel application log tail of queue workers (multiple app instances writing to the same log file) handled by supervisor.

Before:
ezgif-1-77388f9210cf

After:
ezgif-1-0b839d642644

@chalasrchalasr added this to the2.8 milestoneOct 11, 2018
{
if (false === @fwrite($this->stream,$message) || ($newline && (false === @fwrite($this->stream,PHP_EOL)))) {
if ($newline) {
$message .=PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

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

Not reassigning was done purposely to save memory (#18932)

ro0NL reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

well, at least, this code avoids the concatenation when not adding a newline (while all writes where doing a concatenation before#18932 and I'm not sure PHP optimizes the concatenation of empty strings).

But I fear we cannot avoid both the extra allocation and the race condition (you could then ensure that your put the newline in your big message instead of asking the console component to add it though)

rudolfratusinski reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Fine for me.

you could then ensure that your put the newline in your big message instead of asking the console component to add it though

Perhaps this should be mentioned somewhere (docblock and/or symfony-docs?)

@nicolas-grekas
Copy link
Member

Thank you@rudolfratusinski.

gocanto and rudolfratusinski reacted with heart emoji

@nicolas-grekasnicolas-grekas merged commit428dea6 intosymfony:2.8Oct 14, 2018
nicolas-grekas added a commit that referenced this pull requestOct 14, 2018
…olfratusinski)This PR was merged into the 2.8 branch.Discussion----------Fix for race condition in console output stream write| Q             | A| ------------- | ---| Branch?       | 2.8| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |In high throughput environments writing `message` and `PHP_EOL` separately causes race condition issues, where messages might be written in order- message- message- EOL- EOLinstead of- message- EOL- message- EOLAn example below is a laravel application log tail of queue workers  (multiple app instances writing to the same log file) handled by supervisor.Before:![ezgif-1-77388f9210cf](https://user-images.githubusercontent.com/2752769/46792349-bec13180-cd75-11e8-8f91-92f05762f964.gif)After:![ezgif-1-0b839d642644](https://user-images.githubusercontent.com/2752769/46792420-e617fe80-cd75-11e8-9414-4bfc85d9c569.gif)Commits-------428dea6 Fix for race condition in console output stream write
@rudolfratusinski
Copy link
ContributorAuthor

Thank you@rudolfratusinski.

I thank You for a great work you do every single day!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@chalasrchalasrchalasr approved these changes

+1 more reviewer

@ro0NLro0NLro0NL approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

2.8

Development

Successfully merging this pull request may close these issues.

7 participants

@rudolfratusinski@nicolas-grekas@fabpot@stof@ro0NL@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp