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

Client: default to 30s for connection timeout #237

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Network/WebSockets/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Data.IORef (newIORef)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Network.Socket as S
import System.Timeout (timeout)


--------------------------------------------------------------------------------
Expand Down Expand Up @@ -74,10 +75,12 @@ runClientWith host port path0 opts customHeaders app = do
S.setSocketOption sock S.NoDelay 1

-- Connect WebSocket and run client
res <- finally
(S.connect sock (S.addrAddress addr) >>
runClientWithSocket sock fullHost path opts customHeaders app)
(S.close sock)
res <- bracket
(timeout (connectionTimeout opts * 1000 * 1000) $ S.connect sock (S.addrAddress addr))
(const $ S.close sock) $ \maybeConnected -> case maybeConnected of
Nothing -> throwIO $ ConnectionTimeout
Just () -> runClientWithSocket sock fullHost path opts customHeaders app


-- Clean up
return res
Expand Down
4 changes: 4 additions & 0 deletions src/Network/WebSockets/Connection/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

--------------------------------------------------------------------------------
import Data.Int (Int64)
import Data.Monoid (Monoid (..))

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 18 in src/Network/WebSockets/Connection/Options.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant
import Prelude


Expand All @@ -31,6 +31,8 @@
{ connectionOnPong :: !(IO ())
-- ^ Whenever a 'pong' is received, this IO action is executed. It can be
-- used to tickle connections or fire missiles.
, connectionTimeout :: !Int
-- ^ Timeout for connection establishment in seconds. Only used in the client.
, connectionCompressionOptions :: !CompressionOptions
-- ^ Enable 'PermessageDeflate'.
, connectionStrictUnicode :: !Bool
Expand Down Expand Up @@ -59,9 +61,11 @@
-- * Nothing happens when a pong is received.
-- * Compression is disabled.
-- * Lenient unicode decoding.
-- * 30 second timeout for connection establishment.
defaultConnectionOptions :: ConnectionOptions
defaultConnectionOptions = ConnectionOptions
{ connectionOnPong = return ()
, connectionTimeout = 30
, connectionCompressionOptions = NoCompression
, connectionStrictUnicode = False
, connectionFramePayloadSizeLimit = mempty
Expand Down
2 changes: 2 additions & 0 deletions src/Network/WebSockets/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
--------------------------------------------------------------------------------
import qualified Data.ByteString.Builder as Builder
import qualified Data.ByteString.Builder.Extra as Builder
import Control.Applicative (pure, (*>), (<$>),

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 36 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Control.Applicative’ is redundant
(<*), (<*>))
import Control.Exception (Exception)
import qualified Data.Attoparsec.ByteString as A
Expand All @@ -44,7 +44,7 @@
import Data.ByteString.Internal (c2w)
import qualified Data.CaseInsensitive as CI
import Data.Dynamic (Typeable)
import Data.Monoid (mappend, mconcat)

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.0 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.4 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant

Check warning on line 47 in src/Network/WebSockets/Http.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Data.Monoid’ is redundant
import qualified Network.WebSockets.Extensions.Description as Extensions


Expand Down Expand Up @@ -101,6 +101,8 @@
-- | The request was well-formed, but the library user rejected it.
-- (e.g. "unknown path")
| RequestRejected RequestHead ResponseHead
-- | The connection timed out
| ConnectionTimeout
-- | for example "EOF came too early" (which is actually a parse error)
-- or for your own errors. (like "unknown path"?)
| OtherHandshakeException String
Expand Down
Loading