This repository was archived by the owner on Feb 15, 2023. It is now read-only.
Keep-alive request causes segfault on connection close#55
Merged
nikhilm merged 1 commit intonikhilm:masterfrom Jan 26, 2016
Merged
Keep-alive request causes segfault on connection close#55nikhilm merged 1 commit intonikhilm:masterfrom
nikhilm merged 1 commit intonikhilm:masterfrom
Conversation
…to be emitted on a previously deleted request. This would cause a segfault coming from the Qt MOC code where the emit occurs.
Author
|
Just wanted to note, I know at some point you plan on redoing the memory management, but I still find this library very useful and thought this fix might be useful for anyone planning to use the library in its current state! |
nikhilm
added a commit
that referenced
this pull request
Jan 26, 2016
Keep-alive request causes segfault on connection close
Owner
|
Thanks for the contribution. I've merged this, but I no longer intend to work on this project. This might change in the future, but for now I've updated the README with an alternative. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Following the guidelines regarding the memory management of the request object in the docs:
When on a browser that supports keep-alive connections, the closing of the connection will cause a segfault in the MOC file for the QHttpConnection, as shown below:
This segfault occurs because the open connection handles multiple requests, and they are each deleted using the
QObject::deleteLater()slot attached to theQHttpRequest::done()signal. The problem occurs when the keep-alive connection is finally closed. The current request will most likely have already been deleted, but then the connection being closed calls theend()slot on it right here:Even if the request itself was successful, it seems that the deleting of the request invalidates that memory and the call to
QHttpRequest::successful()will sometimes return false, causing theQ_EMITto occur. I used Chrome for testing my current application and it seemed very strange to me that the application would (very unconsistently) crash after sitting for about 5 minutes! It was only after I noticed that the crashes often occured after closing the browser completely.The presented fix is simple and will simply attach a slot to the
QObject::destroyedsignal. We can use this to complete the request if not successful set the request to NULL. ThisinvalidateRequestfunction can now also be used in the connection closed handler.