Skip to content

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Jan 6, 2026

The 'exc' field was used by our debug SSL callbacks. Keep the exception in the normal per-thread state to avoid shared mutable state between threads.

This also avoids a reference count leak if the Python callback raised an exception because it can be called multiple times per SSL operation.

The 'exc' field was used by our debug SSL callbacks. Keep the exception
in the normal per-thread state to avoid shared mutable state between
threads.

This also avoids a reference count leak if the Python callback raised an
exception because it can be called multiple times per SSL operation.
@colesbury
Copy link
Contributor Author

This is like:

But for the exc field.

@colesbury colesbury marked this pull request as ready for review January 6, 2026 19:07
@colesbury colesbury added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 8, 2026
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 8cd4d98 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F143491%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jan 8, 2026
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM, but I would feel safer with proposed assertions to check that assumptions remain valid in the future if the code is modified.

}
Py_RETURN_NONE;
error:
Py_XDECREF(sock);
Copy link
Member

Choose a reason for hiding this comment

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

You might add: assert(exc == NULL);.

}
return PyLong_FromSize_t(count);
error:
Py_XDECREF(sock);
Copy link
Member

Choose a reason for hiding this comment

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

You might add: assert(exc == NULL);.

int retval;
int sockstate;
_PySSLError err;
PyObject *exc;
Copy link
Member

Choose a reason for hiding this comment

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

For consistency with other functions:

Suggested change
PyObject *exc;
PyObject *exc = NULL;

return PyLong_FromSize_t(count);
}

error:
Copy link
Member

Choose a reason for hiding this comment

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

You might add: assert(exc == NULL); here and in the done: label.

Py_RETURN_NONE;

error:
Py_XDECREF(sock);
Copy link
Member

Choose a reason for hiding this comment

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

You might add: assert(exc == NULL);.

@vstinner
Copy link
Member

vstinner commented Jan 9, 2026

The 4 failed builbots are unrelated to this change.

Windows buildbots failed to download zlib external dependency:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1081)

Android buildbot: test_urllibnet failed with:

ERROR: test_getcode (test.test_urllibnet.urlopenNetworkTests.test_getcode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.15/test/test_urllibnet.py", line 107, in test_getcode
    self.assertEqual(e.exception.code, 404)
                     ^^^^^^^^^^^^^^^^
AttributeError: 'URLError' object has no attribute 'code'

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants