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

Various improvements related to waitContainer #79

Merged
merged 4 commits into from
Apr 1, 2022

Conversation

mbg
Copy link
Contributor

@mbg mbg commented Apr 6, 2020

This PR consists of three commits which address #78 in various ways:

  • d3f961d simply documents the issue in waitContainer's documentation
  • b5cd781 adds a new definition defaultUnixManagerSettings. This is just some code refactored out from unixHttpHandler so that unixHttpHandler "/var/run/docker.sock" is equivalent to:
  let settings = defaultUnixManagerSettings "/var/run/docker.sock"
  manager <- newManager settings
  httpHandler manager

This allows the manager to be customised, e.g. to set a different timeout:

  let settings = (defaultUnixManagerSettings "/var/run/docker.sock") {
    managerResponseTimeout = responseTimeoutNone
  }
  manager <- newManager settings
  httpHandler manager
  • 015762a is the most invasive commit and introduces a new function getEndpointTimeout which returns responseTimeoutDefault for all endpoints except WaitContainerEndpoint for which it returns responseTimeoutNone. This is then used in mkHttpRequest to set the value of responseTimeout for the request that is constructed.

I would think that the first two are fairly safe to merge, while the third one may require some thought.

@mbg mbg changed the title Wait timeout Various improvements related to waitContainer Apr 6, 2020
--
-- __NOTE__: this endpoint will not return a response until the container
-- has stopped. This function may therefore fail with a timeout error if
-- the timeout is configured incorrectly in the HTTP manager.

Choose a reason for hiding this comment

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

The timeout isn't necessarily "configured incorrectly", but simply configured to be shorter than the container's execution time, right? It seems like that might be intended behavior from the HTTP manager configuration.

Comment on lines +139 to +152
-- | Use 'httpHandler' with 'defaultUnixManagerSettings' @unixSocketPath@ as
-- argument as an alternative to 'unixHttpHandler' that lets you customise
-- the settings of the 'HTTP.ManagerSettings' value that is returned.
defaultUnixManagerSettings :: FilePath -- ^ The socket to connect to
-> HTTP.ManagerSettings
defaultUnixManagerSettings fp = defaultManagerSettings {
managerRawConnection = return $ openUnixSocket fp
} where openUnixSocket filePath _ _ _ = do
s <- S.socket S.AF_UNIX S.Stream S.defaultProtocol
S.connect s (S.SockAddrUnix filePath)
makeConnection (SBS.recv s 8096)
(SBS.sendAll s)
(S.close s)

Choose a reason for hiding this comment

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

This is superb, and I wonder if it should get pushed upstream?

Comment on lines 109 to 111
getEndpointTimeout :: Endpoint -> HTTP.ResponseTimeout
getEndpointTimeout (WaitContainerEndpoint _) = HTTP.responseTimeoutNone
getEndpointTimeout _ = HTTP.responseTimeoutDefault

Choose a reason for hiding this comment

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

Wait, doesn't this render the NOTE above irrelevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing this! The third commit does make the NOTE from the first irrelevant, but it is a question of whether you want getEndpointTimeout in the code or not. Having it always forces no timeout for the endpoint and no way for the user of the library to override this. Specifying different ManagerSettings and not merging the third commit allows users to specify a timeout themselves, but it is then shared between all endpoints.

Personally, I have been using a version of this library with my changes in production for the past year and the approach with getEndpointTimeout is fine since you can always wrap the call to waitContainer in a timeout yourself. Happy to remove the NOTE if you are happy to merge everything otherwise.

@mbg
Copy link
Contributor Author

mbg commented Feb 20, 2022

Hi @denibertovic and @jprider63 👋🏻 this PR has been open for nearly two years now and I would still like to see something like this merged. Is there anything I can do to help this along? Do you need any help maintaining this library?

@denibertovic
Copy link
Owner

@mbg I'll take a look over the weekend and see if I can get this merged.

@kk-hainq
Copy link

This is awesome!

@denibertovic
Copy link
Owner

@mbg Finally got around to this. I don't have any particular strong opinion about this. But as you say if it works for you in practice for a while now I see no reason why we can't merge it. Thanks!

@denibertovic denibertovic merged commit 81e2f5d into denibertovic:master Apr 1, 2022
@mbg mbg mentioned this pull request Apr 1, 2022
@RobertFischer
Copy link

RobertFischer commented Apr 1, 2022 via email

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.

4 participants