Skip to content

Commit

Permalink
Cloning the message content to prevent data race
Browse files Browse the repository at this point in the history
  • Loading branch information
noctarius committed Oct 1, 2023
1 parent 05da944 commit 0b78967
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package logicalreplicationresolver

import (
"bytes"
"github.com/jackc/pglogrepl"
"github.com/noctarius/timescaledb-event-streamer/internal/containers"
"github.com/noctarius/timescaledb-event-streamer/internal/logging"
Expand Down Expand Up @@ -378,6 +379,10 @@ func (tt *transactionTracker) OnMessageEvent(
xld pgtypes.XLogData, msg *pgtypes.LogicalReplicationMessage,
) error {

// Clone content to release the original array which seems to be a slice of the
// original byte array from pgx
msg.Content = bytes.Clone(msg.Content)

// If the message is transactional we need to store it into the currently collected
// transaction, otherwise we can run it straight away.
if msg.IsTransactional() {
Expand Down

0 comments on commit 0b78967

Please sign in to comment.