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(iot): increment mqtt encoder semaphore value on dealloc #4185

Closed
wants to merge 4 commits into from

Conversation

atierian
Copy link
Member

@atierian atierian commented Jun 17, 2022

Issue #, if available:
#2016

Description of changes:
_encodeSemaphore in AWSMQTTEncoder is created with dispatch_semaphore_create(1). When _encodeSemaphore is released (AWSMQTTEncoder dealloc'd) with a value of 0, a crash occurs due to the value being less than the original value (1).

Here's where the crash is occurring in libdispatch.

void
_dispatch_semaphore_dispose(dispatch_object_t dou,
		DISPATCH_UNUSED bool *allow_free)
{
	dispatch_semaphore_t dsema = dou._dsema;

	if (dsema->dsema_value < dsema->dsema_orig) { /* <--- crash happens here in libdispatch */
		DISPATCH_CLIENT_CRASH(dsema->dsema_orig - dsema->dsema_value,
				"Semaphore object deallocated while in use"); 
	}

	_dispatch_sema4_dispose(&dsema->dsema_sema, _DSEMA4_POLICY_FIFO);
}

This change increments the _encodeSemphore value via dispatch_semaphore_signal(self.encodeSemaphore); in dealloc of AWSMQTTEncoder.

Check points:

  • Added new tests to cover change, if needed
  • All unit tests pass
  • All integration tests pass
  • Updated CHANGELOG.md
  • Documentation update for the change if required
  • PR title conforms to conventional commit style

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

@atierian atierian marked this pull request as ready for review June 20, 2022 18:22
@atierian atierian requested review from a team and awsmobilesdk as code owners June 20, 2022 18:23
@brennanMKE
Copy link
Contributor

This PR will be replaced by #4211 which eliminates the semaphores from the IoT client code.

@brennanMKE brennanMKE closed this Jul 12, 2022
@brennanMKE brennanMKE deleted the fix/imbalanced-semaphore-dealloc branch July 12, 2022 04:15
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.

3 participants