GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix socket leaks by it-x · Pull Request #351 · python/cpython

Conversation

@it-x

@it-x it-x commented Feb 27, 2017

Copy link
Copy Markdown

The close method moved to finally block, so closing a socket will occur even in case of exception

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@it-x
Fix socket leaks
bb98ca3
@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Feb 27, 2017
@the-knights-who-say-ni

the-knights-who-say-ni commented Feb 27, 2017

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, please create one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign the PSF contributor agreement. The "bugs.python.org username " requested by the form is the "Login name" field under "Your Details".
  4. If you just signed the CLA, please wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@it-x

it-x commented Feb 28, 2017

Copy link
Copy Markdown
Author

I'm signed the CLA

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brettcannon brettcannon removed the CLA not signed label Feb 28, 2017
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 28, 2017
vstinner
vstinner reviewed Mar 2, 2017
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

"with conn:" cannot be used?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Mar 2, 2017

Copy link
Copy Markdown
Member

Oh, ignore my comment, I missed the Python version (2.7): in Python 2.7, socket.socket doesn't support the context manager protocol :-(

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner requested changes Mar 2, 2017
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

retrbinary(), retrlines() and storelines() at least have the same bug, no? Can you please fix similar bugs in other functions?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@it-x
Fixed sockets leak
9ae87b8
@it-x

it-x commented Mar 2, 2017

Copy link
Copy Markdown
Author

Ok, I did

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner approved these changes Mar 2, 2017
View reviewed changes
@Mariatta

Mariatta commented Mar 4, 2017

Copy link
Copy Markdown
Member

Should there be an issue in the bug tracker for this?

Also, I'm applying the cherry-pick for 2.7 label here to make it more obvious that this is for 2.7 branch :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Mariatta Mariatta added the cherry-pick for 2.7 label Mar 4, 2017
serhiy-storchaka
serhiy-storchaka reviewed Apr 2, 2017
View reviewed changes
Comment thread Lib/ftplib.py
callback(line)
finally:
if fp:
fp.close()

@serhiy-storchaka serhiy-storchaka Apr 2, 2017

Copy link
Copy Markdown
Member

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.

Can fp.close() fail? If yes, conn will be not closed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Apr 3, 2017

Copy link
Copy Markdown
Member

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.

The file is in read mode, I don't see why fp.close() would fail.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Apr 3, 2017

Copy link
Copy Markdown
Member

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.

An alternative is to use two try/finally: conn and then fp. It would avoid "fp = None" as well. Do you think that it's worth it @serhiy-storchaka ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Apr 3, 2017

Copy link
Copy Markdown
Member

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.

KeyboardInterrupt ;-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka

serhiy-storchaka commented Apr 2, 2017

Copy link
Copy Markdown
Member

You can use contextlib.closing().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Apr 3, 2017
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

LGTM, but I prefer to wait for @serhiy-storchaka for retrlines().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/ftplib.py
callback(line)
finally:
if fp:
fp.close()

@vstinner vstinner Apr 3, 2017

Copy link
Copy Markdown
Member

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.

An alternative is to use two try/finally: conn and then fp. It would avoid "fp = None" as well. Do you think that it's worth it @serhiy-storchaka ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka
serhiy-storchaka approved these changes Apr 3, 2017
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

LGTM. I think we can ignore very small issue in retrlines() in 2.7. I just remembered of alternatives for the case if you missed them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
vstinner merged commit d64146c into python:2.7 Apr 3, 2017
@vstinner

vstinner commented Apr 3, 2017

Copy link
Copy Markdown
Member

Thank you @J0l-lnny for your fix! I merged your PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 3, 2017

Copy link
Copy Markdown
Member

@serhiy-storchaka: "LGTM. I think we can ignore very small issue in retrlines() in 2.7."

Right, thank you for your review. If someone wants to handle the most complex corner cases, I suggest to focus on the master branch. Right now, the master branch uses a "nested" with which isn't ideal since it doesn't handle exceptions in creating fp fails (or is interrupted by CTRL+c or whatever):

Extract of ftplib.py in the master branch:

    def retrlines(self, cmd, callback = None):
        ...
        with self.transfercmd(cmd) as conn, \
                 conn.makefile('r', encoding=self.encoding) as fp:
        ...

At least, it ensures that conn and fp are closed properly, right?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Apr 3, 2017

Copy link
Copy Markdown
Member

What is wrong with a nested with? The resources management in the master branch looks correct to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 3, 2017

Copy link
Copy Markdown
Member

What is wrong with a nested with? The resources management in the master branch looks correct to me.

If makefile() raises an exception, conn is not closed. Well, in fact I'm not sure, that's why I was asking :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Apr 3, 2017

Copy link
Copy Markdown
Member

It is properly closed.

with a, b:
        ...

is just a syntax sugar for

with a:
    with b:
        ...

You perhaps missed with deprecated and removed

with contextlib.nested(a, b):
        ...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 3, 2017 via email

Copy link
Copy Markdown
Member
(...) is just a syntax sugar for "with a: with b: ..."
Ok! master is fine in that case ;-) Thanks for the confirmation. Note: By "nested", I really mean "with expr1 as a, expr2 as b: ...".
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@it-x
it-x deleted the 2.7 branch April 7, 2017 18:22
jaraco pushed a commit that referenced this pull request Dec 2, 2022
@dependabot-preview
Bump celery from 4.4.2 to 4.4.6 (#351)
314ea0c
Bumps [celery](https://github.com/celery/celery) from 4.4.2 to 4.4.6.
- [Release notes](https://github.com/celery/celery/releases)
- [Changelog](https://github.com/celery/celery/blob/master/Changelog.rst)
- [Commits](celery/celery@4.4.2...v4.4.6)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
SonicField added a commit to SonicField/cpython that referenced this pull request May 12, 2026
@SonicField
docs/ops: NBS handle-namespace collision codification + proposed fix
9e2b652
Codification commit python#3 in post-c4 codification batch per supervisor
16:05:15Z dispatch. Anchors librarian 06:16Z (handle-namespace recurring
per-cycle observation) + pythia python#350 (cross-project collision queue) +
python#351 (per-cycle prediction confirmed by repeated fixup workarounds at
07:12Z, 08:10Z, 09:11Z, 10:12Z, 11:13Z, 12:50:32Z, 13:52:13Z, 14:53:48Z).

Documents:
- Cross-project handle collision class (multiple Phoenix-style teams on
  same OS user share role names like 'scribe', 'medic')
- Proximate driver: nbs-sidecar-restart line 153 handle-strip collapses
  compound handles like supervisor-vib -> supervisor, erasing project
  distinctness when project name follows role
- Current operational workaround: --root=PATH filter on every fixup call
- Proposed one-line fix: add SC_ROOT to dedup key so cross-project
  sidecars stay separate by default (lines 167 + 169 area in script)

The fix is local to nbs-sidecar-restart and does not require coordination
with nbs-sidecar itself. --root=PATH becomes an additional filter rather
than the only protection.

Doc-only commit; not modifying nbs-sidecar-restart in this Phoenix repo
(out of phoenix tree). Implementation deferred to whoever ships the
script change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@it-x @the-knights-who-say-ni @vstinner @Mariatta @serhiy-storchaka @brettcannon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.