Reputation: 9
When I create a connection using sqlx and attempt to start a transaction with the BeginTxx method, and then concurrently access MySQL through multiple goroutines initiated by the errgroup.Group method within the transaction, I encountered an error with the connection being dropped.
ctx := context.Background()
txx, err := common.GetDBApp().BeginTxx(ctx, nil)
require.NoError(t, err)
group, _ := errgroup.WithContext(ctx)
f := func() error {
var id uint64
err = txx.Get(&id, `select id from t_id where id = 1`)
require.NoError(t, err)
return nil
}
for i := 0; i < 100; i++ {
group.Go(f)
}
group.Wait()
I hope to understand the causes of this error.
```go
Upvotes: 0
Views: 50