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

make controller_run_result movable and expose it as start_result #108

Merged
merged 14 commits into from
Jan 30, 2022

Conversation

0x00002a
Copy link
Contributor

@0x00002a 0x00002a commented Jan 16, 2022

Related to #106 and #107.

5874a5a implemented part of this but there is a subtle bug in it which shouldn't exist in this one. Feel free to close and/or cherry pick the move changes as the rest may be unwanted while #107 is open, but make sure to include 6456a16 as I accidentally removed the work guard when merging it with my local changes.

Also of note is the message in 6456a16, in which I discovered why we need a work guard for the io context.

This actually was informative because it showed how m_workguard actually
does matter. See if there is no work guard, and the user calls
run() on a _client_ controller, then enough time elapses so that
all work is complete and there is a pause before new work is added,
the io_context::run() will return for each of the threads, meaning that
in actual fact queuing more actions via the controller (which is valid
after calling start) would not actually do anything.

tl;dr nasty obscure bug, keep the workguard its needed for clients
@Tectu
Copy link
Owner

Tectu commented Jan 16, 2022

Well, that was some unfortunate timing :p

5874a5a implemented part of this but there is a subtle bug in it which shouldn't exist in this one.

Could you be more specific? I must be missing something obvious... Would love to hear about it.

@0x00002a
Copy link
Contributor Author

0x00002a commented Jan 16, 2022

5874a5a implemented part of this but there is a subtle bug in it which shouldn't exist in this one.

Could you be more specific? I must be missing something obvious... Would love to hear about it.

The threads spawned by controller_run_result capture this and then access the m_io_context through it. The issue here is that the function passed to the thread ctor only runs after the thread is spawned, meaning if the code to move the object is executed first, as is possible in the test case which does it on the next line (and which only happened for me when a debugger wasn't attached, that was fun), then the m_io_context being accessed through the this pointer was the one that had already been moved from and now pointed to nullptr. All in all I'm very glad I wrote a test case or I would never have caught that one :p

Also it doesn't check in run() for if the object has been moved from, meaning it could result in UB via nullptr deference there. In this I've thrown an exception but I'm not sure if that should be an assert

@Tectu
Copy link
Owner

Tectu commented Jan 16, 2022

The threads spawned by controller_run_result capture this and then access the m_io_context through it. The issue here is that the function passed to the thread ctor only runs after the thread is spawned, meaning if the code to move the object is executed first, as is possible in the test case which does it on the next line (and which only happened for me when a debugger wasn't attached, that was fun), then the m_io_context being accessed through the this pointer was the one that had already been moved from and now pointed to nullptr. All in all I'm very glad I wrote a test case or I would never have caught that one :p

Ouch... that one would definitely have made for some very, very unpleasant nights of debugging down the road. I am very glad that you caught that one... - Eagle eyes 😉

Also it doesn't check in run() for if the object has been moved from, meaning it could result in UB via nullptr deference there. In this I've thrown an exception but I'm not sure if that should be an assert

Now that was just a stupid oversight - should have taken the courtesy to get some sleep before committing this - sorry!

Not sure whether we should:

  • Revert my changes so this becomes easily mergable
  • Merge it by hand
  • You updating your PR so it can be merged into main as part of the PR

@0x00002a
Copy link
Contributor Author

Well I don't really have much more time to spend on this, and prolly won't for a few days unfortunately so it might be best to roll back 5874a5a since it isn't safe to move the object anyway and then merge this when it implements whatever is decided for #107, since otherwise its likely going to make the solution a breaking change.

I'm pretty sure I can just resolve conflicts by hand on github though by just not accepting 5874a5a when merging

@Tectu
Copy link
Owner

Tectu commented Jan 16, 2022

I'm a bit tight on time as well. I will revert my commit which introduced the bug you discovered/mentioned so that main and circle back to this later.

Thank you for all the time you invest into this. It's greatly appreciated :)

Tectu added a commit that referenced this pull request Jan 16, 2022
This reverts commit 5874a5a.
The reverted commit contains a bug discovered by @0x00002a mentioned in #108
@0x00002a
Copy link
Contributor Author

I've done the renames suggested in #107. I also renamed the header files and such, not sure if routing_context is the final name we want to go with, but start_result is now session instead and is exposed by both the client controller and server routing context

@Tectu
Copy link
Owner

Tectu commented Jan 30, 2022

Nice work!
Seems like we have some demo fixing to do.

@Tectu Tectu merged commit edb7355 into Tectu:main Jan 30, 2022
@0x00002a 0x00002a mentioned this pull request Feb 6, 2022
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