Skip to content

Commit

Permalink
Bugfix: crash during startup because of missing 'x-delayed-type' (#620)
Browse files Browse the repository at this point in the history
* Clone arguments before modifying them

* Update changelog
  • Loading branch information
spuun authored Jan 8, 2024
1 parent d4d3ad3 commit 75fcf09
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- A bug causing faulty definition frames for delayed exchanges, preventing LavinMQ from starting [#620](https://github.com/cloudamqp/lavinmq/pull/620)

## [1.2.7] - 2023-12-12

- Version 1.2.6 may not include the bumped version of lavinmq, so instead use version 1.2.7
Expand Down
15 changes: 15 additions & 0 deletions spec/vhost_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ describe LavinMQ::VHost do
Server.vhosts["test"].exchanges["e"].should_not be_nil
end

it "should be able to persist durable delayed exchanges when type = x-delayed-message" do
# This spec is to verify a fix where a server couldn't start again after a crash if
# an delayed exchange had been declared by specifiying the type as "x-delayed-message".
Server.vhosts.create("test")
v = Server.vhosts["test"].not_nil!
arguments = AMQ::Protocol::Table.new({"x-delayed-type": "direct"})
v.declare_exchange("e", "x-delayed-message", true, false, arguments: arguments)

# Start a new server with the same data dir as `Server` without stopping
# `Server` first, because stopping would compact definitions and therefore "rewrite"
# the definitions file. This is to simulate a start after a "crash".
# If this succeeds we assume it worked...?
LavinMQ::Server.new(DATA_DIR)
end

it "should be able to persist durable queues" do
Server.vhosts.create("test")
v = Server.vhosts["test"].not_nil!
Expand Down
1 change: 1 addition & 0 deletions src/lavinmq/vhost.cr
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ module LavinMQ
when "headers"
HeadersExchange.new(vhost, name, durable, auto_delete, internal, arguments)
when "x-delayed-message"
arguments = arguments.clone
type = arguments.delete("x-delayed-type")
raise Error::ExchangeTypeError.new("Missing required argument 'x-delayed-type'") unless type
arguments["x-delayed-exchange"] = true
Expand Down

0 comments on commit 75fcf09

Please sign in to comment.