Hello, I have a code snippet equivalent to this one:

rows, err := stmt.QueryContext(ctx)
if err != nil {
    return info, nil, err
}
defer rows.Close()

var data sql.RawBytes
for rows.Next() {
    err = rows.Scan(&data)
    if err != nil {
        return nil, err
    }
    // if ctx is canceled around this point, rows.Close() will be called 
and the data can e overwritten, causing a data race
    _ = data[0] // <--- possible concurrent read here and write inside 
driver.Rows.Close()
}

And as the comments say, if the context is cancelled, there's a possibility 
of a data race where this goroutine is trying to read data[0], and another 
goroutine can be writing to it, cause the sql package calls 
driver.Rows.Close() 
(from 
https://github.com/golang/go/blob/176b63e7113b82c140a4ecb2620024526c2c42e3/src/database/sql/sql.go#L2974
 
)

I've opened an issue about this on github ( 
https://github.com/golang/go/issues/53970 ), but was told that's not the 
proper forum to talk about data races.

Any help would be appreciated, thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6c0345cb-5e39-4db0-90c8-6cab97d0f0ean%40googlegroups.com.

Reply via email to