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

Bump Halibut so HalibutRuntime is Disposed correctly on Tentacle Shutdown #716

Merged

Conversation

nathanwoctopusdeploy
Copy link
Contributor

@nathanwoctopusdeploy nathanwoctopusdeploy commented Dec 2, 2023

Background

Fix a bug where Tentacle does not dispose of the HalibutRuntime on shutdown.

This can result in the listening port for a listening tentacle not being freed up quickly and stop the tentacle service from being stopped and started quickly.

The HalibutRuntime only had a DisposeAsync method, Dispose has also been added so it works correctly with the version of Autofac used in Tentacle.

Fixes #725

[sc-66309]

How to review this PR

Quality ✔️

Pre-requisites

  • I have read How we use GitHub Issues for help deciding when and where it's appropriate to make an issue.
  • I have considered informing or consulting the right people, according to the ownership map.
  • I have considered appropriate testing for my change.

@@ -134,5 +135,19 @@ IPEndPoint GetEndPointToListenOn()
public void Stop()
{
}

public void Dispose()
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 This struck me as odd that we have to do this, as Autofac naturally disposes of dependencies given to a class.

I tested this, and this is indeed true. So why did we need to do this for Halibut?

Turns out it's the difference between IDisposable and IAsyncDisposable. The former will get disposed by Autofac, and the latter will not 😑.

Since we recently removed the IDisposable interface from Halibut, this is why it has stopped being disposed of by Autofac.

Knowing all this, it made me wonder:

  • What we did here will work. But would it be better or worse to put back the HalibutRuntime.Dispose method as an alternative to solving this problem?
  • Also, we end up double disposing log, as Autofac also disposes it (I tested it to make sure).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, we end up double disposing log, as Autofac also disposes it (I tested it to make sure).

Ahh yep, good catch, we get given the log so we shouldn't dispose of it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we did here will work. But would it be better or worse to put back the HalibutRuntime.Dispose method as an alternative to solving this problem?

Ahh yeh I see, again it's given to us so we shouldn't need to do this. If we bump autofac then it knows how to handle IAsyncDisposable but that's a relatively big change.

We could add Dispose back, or wrap it a little bit to fix the issue here until we are ready to bump autofac

{
var startScriptCommand = new LatestStartScriptCommandBuilder()
.WithScriptBodyForCurrentOs(
$@"cd ""{clientAndTentacle.RunningTentacle.TentacleExe.DirectoryName}""
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, do you get Tentacle to restart by running a command through Tentacle to restart itself?

Wouldn't that interfere with itself? I think I'm missing something... 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what Dynamic Workers Service does to Dynamic Workers!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a hectic mess of things you probably shouldn't really do 😆

Copy link
Contributor

@sburmanoctopus sburmanoctopus left a comment

Choose a reason for hiding this comment

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

Nice test for checking works correctly.

I'll leave it to you to decide what to do about:

  • The double dispose of log
  • Whether we want to solve this with reintroducing Dispose to HalibutRuntime instead.

@nathanwoctopusdeploy nathanwoctopusdeploy force-pushed the sast/fix-tentacle-not-disposing-of-halibutruntime branch 2 times, most recently from bc625a2 to 6c79ffb Compare December 4, 2023 09:35
…ks with the autofac container.

Add tests to ensure a service can restart itself and that ports are being released
@nathanwoctopusdeploy nathanwoctopusdeploy force-pushed the sast/fix-tentacle-not-disposing-of-halibutruntime branch from 6c79ffb to 49b0176 Compare December 4, 2023 13:43
@nathanwoctopusdeploy nathanwoctopusdeploy changed the title Dispose of the HalibutRuntime when Tentacle is stopped Bump Halibut so HalibutRuntime is Disposed correctly on Tentacle Shutdown Dec 4, 2023
Copy link

@nathanwoctopusdeploy nathanwoctopusdeploy enabled auto-merge (squash) December 5, 2023 03:46
@nathanwoctopusdeploy nathanwoctopusdeploy merged commit e273d83 into main Dec 5, 2023
48 checks passed
@nathanwoctopusdeploy nathanwoctopusdeploy deleted the sast/fix-tentacle-not-disposing-of-halibutruntime branch December 5, 2023 04:00
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.

Restarting a Listening Tentacle on Windows results in a port is already in use error.
2 participants