wagslane / go-rabbitmq

A wrapper of streadway/amqp that provides reconnection logic and sane defaults
https://blog.boot.dev/golang/connecting-to-rabbitmq-in-golang-easy/
MIT License
805 stars 128 forks source link

Segmentation violation when publishing twice on non-existing exchange #106

Closed bernhard-herzog closed 8 months ago

bernhard-herzog commented 1 year ago

When trying to publish messages to an exchange that hasn't been created yet multiple times, I get a segmentation violation in amqp091-go. Trying to publish at least twice appears to be crucial for reproduction.

Stack:

github.com/rabbitmq/amqp091-go.(*Channel).setClosed(...)
    [...]pkg/mod/github.com/rabbitmq/amqp091-go@v1.5.0/channel.go:94
github.com/rabbitmq/amqp091-go.updateChannel(...)
    [...]pkg/mod/github.com/rabbitmq/amqp091-go@v1.5.0/types.go:329
github.com/rabbitmq/amqp091-go.(*Connection).dispatchN(0xc000002140, {0x6a0880, 0xc00014e108?})
    [...]pkg/mod/github.com/rabbitmq/amqp091-go@v1.5.0/connection.go:539 +0xbc
github.com/rabbitmq/amqp091-go.(*Connection).demux(0xc00004ef28?, {0x6a0880, 0xc00014e108})
    [...]pkg/mod/github.com/rabbitmq/amqp091-go@v1.5.0/connection.go:500 +0x5b
github.com/rabbitmq/amqp091-go.(*Connection).reader(0xc000002140, {0x7f51d4581058?, 0xc000014010?})
    [...]pkg/mod/github.com/rabbitmq/amqp091-go@v1.5.0/connection.go:600 +0x23d
created by github.com/rabbitmq/amqp091-go.Open
    [...]pkg/mod/github.com/rabbitmq/amqp091-go@v1.5.0/connection.go:265 +0x34c

Code to reproduce:

    conn, err := rabbitmq.NewConn(
        url,
        rabbitmq.WithConnectionOptionsLogging,
    )
    check(err)
    defer conn.Close()

    log.Print("NewPublisher")
    publisher, err := rabbitmq.NewPublisher(
        conn,
        rabbitmq.WithPublisherOptionsLogging,
    )
    check(err)
    defer publisher.Close()

    log.Print("Publish")
    check(publisher.Publish(
        []byte("My Message"),
        []string{"my-route"},
        rabbitmq.WithPublishOptionsExchange("my-exchange"),
    ))

    select {
    case <-time.After(10 * time.Second):
    }

    log.Print("Publish")
    check(publisher.Publish(
        []byte("My Message 2"),
        []string{"my-route"},
        rabbitmq.WithPublishOptionsExchange("my-exchange"),
    ))

I can observe this with go-rabbitmq v0.12.0 and go-rabbitmq v0.11.1

wagslane commented 1 year ago

Did you try setting the exchange options "declare" to true?