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

Nanostack: release connect_semaphore only when it is pending #10462

Conversation

michalpasztamobica
Copy link
Contributor

Description

The rationale behind this PR is the following. It often happens that a Thread device gets local connectivity before the global connectivity. In such case the network handler is called twice and each time releases the _connect_semaphore. If the device disconnects and then connects again, the previously released (incremented) semaphore will be available for immediate decrementation and the connect will not really block.
This fixes failures in NETWORKINTERFACE_CONN_DISC_REPEAT test for Thread protocol.

I also noticed some detailed guidelines about when to consider a Thread device connected, but those are Thread-specific, and should not be implemented in general Nanostack network_handler. It made me wonder however if the semaphore should perhaps be released in the lower layer, so a Thread device unblocks at a different point than a LOWPAN device, perhaps?

@0xc0170 , does the CI for PRs run any Nanostack tests? I assumed not and hacked our CI to run this commit for me on multiple platforms to check that nothing gets broken, but I wonder if I should have relied on CI?

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@SeppoTakalo
@KariHaapalehto
@VeijoPesonen

@michalpasztamobica michalpasztamobica force-pushed the nanostack_semaphore_release_connecting branch from 1f211da to b7d460d Compare April 24, 2019 08:25
Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Good example of why I hate semaphores so much. The counting is almost always a hindrance, not a help.

I'd be inclined to tear it all up and use a ConditionVariable instead, which would give better control of potentially complex conditions like this, but this will do.

Only release if the current _connect_status is CONNECTING. If the semaphore is released many times for each connect, then the next connect will not wait(), as it will be able to decrement the semaphore imediatelly.
@michalpasztamobica michalpasztamobica force-pushed the nanostack_semaphore_release_connecting branch from b7d460d to 2b26a62 Compare April 24, 2019 08:31
@adbridge
Copy link
Contributor

ci started

@mbed-ci
Copy link

mbed-ci commented Apr 26, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

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.

5 participants