Skip to content

Commit

Permalink
close per-message deflate contexts on close
Browse files Browse the repository at this point in the history
  • Loading branch information
rawhat committed May 23, 2024
1 parent 3f99813 commit c6f84ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages = [
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "glisten", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "glisten", source = "hex", outer_checksum = "CF3A9383E9BA4A8CBAF2F7B799716290D02F2AC34E7A77556B49376B662B9314" },
{ name = "gramps", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "7A342373F0BA751DEC58EE69BA23F08DC5E833521B7191DAD37F3A2FD9F098A0" },
{ name = "gramps", version = "2.0.1", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "FBB7EA641C8A1EF02C0E938B6045A1360B925E5E65BAD0E228C4AEF6C6933722" },
{ name = "hackney", version = "1.20.1", build_tools = ["rebar3"], requirements = ["certifi", "idna", "metrics", "mimerl", "parse_trans", "ssl_verify_fun", "unicode_util_compat"], otp_app = "hackney", source = "hex", outer_checksum = "FE9094E5F1A2A2C0A7D10918FEE36BFEC0EC2A979994CFF8CFE8058CD9AF38E3" },
{ name = "hpack_erl", version = "0.3.0", build_tools = ["rebar3"], requirements = [], otp_app = "hpack", source = "hex", outer_checksum = "D6137D7079169D8C485C6962DFE261AF5B9EF60FBC557344511C1E65E3D95FB0" },
{ name = "idna", version = "6.1.1", build_tools = ["rebar3"], requirements = ["unicode_util_compat"], otp_app = "idna", source = "hex", outer_checksum = "92376EB7894412ED19AC475E4A86F7B413C1B9FBB5BD16DCCD57934157944CEA" },
Expand Down
34 changes: 33 additions & 1 deletion src/mist/internal/websocket.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,24 @@ pub fn initialize_connection(
selector,
)
}
actor.Stop(reason) -> actor.Stop(reason)
actor.Stop(reason) -> {
let _ =
option.map(state.permessage_deflate, fn(contexts) {
compression.close(contexts.deflate)
compression.close(contexts.inflate)
})
actor.Stop(reason)
}
}
})
|> result.lazy_unwrap(fn() {
logging.log(logging.Error, "Received a malformed WebSocket frame")
on_close(state.user)
let _ =
option.map(state.permessage_deflate, fn(contexts) {
compression.close(contexts.deflate)
compression.close(contexts.inflate)
})
actor.Stop(process.Abnormal(
"WebSocket received a malformed message",
))
Expand All @@ -186,6 +198,11 @@ pub fn initialize_connection(
)
}
actor.Stop(reason) -> {
let _ =
option.map(state.permessage_deflate, fn(contexts) {
compression.close(contexts.deflate)
compression.close(contexts.inflate)
})
on_close(state.user)
actor.Stop(reason)
}
Expand All @@ -198,17 +215,32 @@ pub fn initialize_connection(
)
})
|> result.lazy_unwrap(fn() {
let _ =
option.map(state.permessage_deflate, fn(contexts) {
compression.close(contexts.deflate)
compression.close(contexts.inflate)
})
on_close(state.user)
actor.Stop(process.Abnormal("Crash in user websocket handler"))
})
}
Valid(SocketClosedMessage) -> {
let _ =
option.map(state.permessage_deflate, fn(contexts) {
compression.close(contexts.deflate)
compression.close(contexts.inflate)
})
on_close(state.user)
actor.Stop(process.Normal)
}
// TODO: do we need to send something back for this?
Invalid -> {
logging.log(logging.Error, "Received a malformed WebSocket frame")
let _ =
option.map(state.permessage_deflate, fn(contexts) {
compression.close(contexts.deflate)
compression.close(contexts.inflate)
})
on_close(state.user)
actor.Stop(process.Abnormal(
"WebSocket received a malformed message",
Expand Down

0 comments on commit c6f84ad

Please sign in to comment.