Skip to content
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 mqtt3 client shutdown callback #498

Merged
merged 67 commits into from
Aug 28, 2023
Merged

Fix mqtt3 client shutdown callback #498

merged 67 commits into from
Aug 28, 2023

Conversation

xiazhvera
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xiazhvera xiazhvera marked this pull request as ready for review August 22, 2023 15:51
@@ -1549,117 +1549,6 @@ def test_operation_statistics_uc1(self):
client.stop()
callbacks.future_stopped.result(TIMEOUT)

# ==============================================================
# 5to3 ADAPTER TEST CASES
# ==============================================================
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The adapter tests are moved to its own file.

@@ -374,9 +382,11 @@ PyObject *aws_py_mqtt_client_connection_new(PyObject *self, PyObject *args) {
Py_DECREF(self_proxy);
proxy_new_failed:
use_websockets_failed:
set_on_closed_failed:
Copy link
Contributor

Choose a reason for hiding this comment

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

I've come to hate this pattern for cleanup. We did it early on, but it is far better (imo) to have a failure path that can safely be executed from all branch points. If scoping is an issue, declarations can be moved up to the top of the function.

Would much rather see something like this:

on_failure:

   Py_XDECREF(self_proxy); 
   aws_mqtt_client_connection_release(py_connection->native);
   aws_mem_release(allocator, py_connection);
   return NULL;

Copy link
Contributor

@bretambrose bretambrose left a comment

Choose a reason for hiding this comment

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

Fix n ship

aws_mem_release(allocator, py_connection);
creation_failed:
Py_XDECREF(self_proxy);
if (py_connection) {
Copy link
Contributor

Choose a reason for hiding this comment

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

py_connection has to be non-null at this point.
Also, maybe just "on_error:" rather than "creation_failed:"

creation_failed:
Py_XDECREF(self_proxy);
if (py_connection) {
if (py_connection->native) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You also don't need to null check this either. release handles a null invocation. The original suggestion would work verbatim.

@xiazhvera xiazhvera merged commit 74e0538 into main Aug 28, 2023
63 checks passed
@xiazhvera xiazhvera deleted the 5to3adapter branch August 28, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants