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.
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
Add
shutdown_socket()
function for follow up of #505 #506base: main
Are you sure you want to change the base?
Add
shutdown_socket()
function for follow up of #505 #506Changes from 24 commits
0af50a5
e5129c5
1b00ed3
de2fbde
9ea9f1d
d9a67a2
996896c
e3b0ea1
30a9446
276d7b4
93adf2e
d27c743
ef3345b
311205d
c0d59db
96b146a
e93f266
0f89b4c
aa6fe33
0c7be7f
62354ab
6b8bd91
1edd1e3
8334783
048a5b3
5d34858
7e7d912
2759ae1
7f0ad69
89f7b91
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
It looks like this function assumes the
lf_outbound_socket_mutex
mutex lock is held when the function is called. This needs to be stated in the documentation and checked for all calls to the function.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.
This function doesn't really assume the mutex lock is held always.
In normal socket shutdown cases (normal termination), they do assume there is a mutex lock, for example,
federate.c
'sclose_inbound_socket()
,close_outbound_socket()
, andrti_remote.c
'shandle_federate_failed()
,handle_federate_resign()
does hold the mutexes.However, some corner cases that handle abnormal termination, do not assume that there are mutex locks.
For example, in
federate.c
'slisten_to_rti_TCP()
function, when the 1byte header read fails, it does not lock any mutexes, and just shutdowns the socket.Also, in
rti_remote.c
'srespond_to_erroneous_connections()
function, which is running in a separate thread, it does not lock any mutexes and just shutdowns the socket.So, what I thought was that the user should handle the mutex if it is needed.
Of course, I could add one line in the documentation of this function, such as
Mutex locks should be considered before calling this function.
or would there be any other suggestions?
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.
Is the code correct without this specific mutex? Note that it can't be any mutex... All callers have to use the same mutex...
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.
Sorry, professor, I think I didn't understand your question in the first place.
What I understood was, "Don't you need this
lf_outbound_socket_mutex
inside this function?" Am I correct? For that question, as I explained, some cases need mutexes, and some cases do not. So, I thought that the function caller should set the mutex on their own.If I misunderstood your question, could you please clarify your question?
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.
Among other things, the function does this:
If this function can be called from multiple threads, then two threads can both get past the first check and then proceed to try to simultaneously close the socket. The only way this code is safe is if you can assure that no more than one thread can call this function.
If more than one thread can call the function, then the above code is only correct if all threads that can call the function acquire the same mutex before calling it. Otherwise, the code is not correct.
One way to ensure safety is to assure that anywhere this is called without acquiring a mutex, only one thread is running. Alternatively, you would need to assure that no other thread that might be running can call this function. This may be quite difficult to assure.
One solution would be to acquire a mutex within this function. But this may be inefficient because some callers may already hold the relevant mutex. In the absence of such a local mutex, you would need to assure that all callers hold the mutex, and it would have to be clearly documented that this is required to call this function.