mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
server: catch TimeoutThread and InvalidRequest exceptions in websocket connections
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8014 GitOrigin-RevId: eef2d1ce99ec87bb239584c3ca4a9f056131b5cc
This commit is contained in:
parent
782c905bf4
commit
2b1d5be10a
@ -329,6 +329,7 @@ common lib-depends
|
||||
, these
|
||||
, time >= 1.9
|
||||
, time-compat
|
||||
, time-manager
|
||||
, transformers
|
||||
, transformers-base
|
||||
, unordered-containers >= 0.2.12
|
||||
|
@ -66,11 +66,13 @@ import Hasura.Server.Prometheus
|
||||
)
|
||||
import ListT qualified
|
||||
import Network.Wai.Extended (IpAddress)
|
||||
import Network.Wai.Handler.Warp qualified as Warp
|
||||
import Network.WebSockets qualified as WS
|
||||
import Refined (unrefine)
|
||||
import StmContainers.Map qualified as STMMap
|
||||
import System.IO.Error qualified as E
|
||||
import System.Metrics.Prometheus.Counter qualified as Prometheus.Counter
|
||||
import System.TimeManager qualified as TM
|
||||
|
||||
newtype WSId = WSId {unWSId :: UUID.UUID}
|
||||
deriving (Show, Eq, Hashable)
|
||||
@ -343,14 +345,26 @@ createServerApp getMetricsConfig wsConnInitTimeout (WSServer logger@(L.Logger wr
|
||||
messageHandler = _hOnMessage wsHandlers
|
||||
closeHandler = _hOnClose wsHandlers
|
||||
|
||||
-- It's not clear what the unexpected exception handling story here should be. So at
|
||||
-- least log properly and re-raise:
|
||||
logUnexpectedExceptions = handle $ \(e :: SomeException) -> do
|
||||
writeLog $
|
||||
L.UnstructuredLog L.LevelError $
|
||||
fromString $
|
||||
"Unexpected exception raised in websocket. Please report this as a bug: " <> show e
|
||||
throwIO e
|
||||
logUnexpectedExceptions = flip catches handlers
|
||||
where
|
||||
handlers =
|
||||
[ -- this exception occurs under the normal course of the web server running. Also fairly common during shutdowns.
|
||||
-- Common suggestion is to gobble it.
|
||||
-- Refer: https://hackage.haskell.org/package/warp-3.3.24/docs/src/Network.Wai.Handler.Warp.Settings.html#defaultShouldDisplayException
|
||||
Handler $ \(_ :: TM.TimeoutThread) -> pure (),
|
||||
Handler $ \(e :: Warp.InvalidRequest) -> do
|
||||
writeLog $
|
||||
L.UnstructuredLog L.LevelError $
|
||||
fromString $
|
||||
"Client exception: " <> show e
|
||||
throwIO e,
|
||||
Handler $ \(e :: SomeException) -> do
|
||||
writeLog $
|
||||
L.UnstructuredLog L.LevelError $
|
||||
fromString $
|
||||
"Unexpected exception raised in websocket. Please report this as a bug: " <> show e
|
||||
throwIO e
|
||||
]
|
||||
|
||||
shuttingDownReject =
|
||||
WS.RejectRequest
|
||||
|
Loading…
Reference in New Issue
Block a user