Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed panic on concurrent context key map write #1284

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

Wang
Copy link
Contributor

@Wang Wang commented Apr 25, 2024

Summary

When open a ClickHouse DB connection through the HTTP protocol and using the WithDeadline context during transaction execution, there is a small probability of concurrent writes to a map, which can lead to a panic. The reason is that when the PrepareContext function is called, it creates a goroutine to read data through the readData function. The readData function updates the key of “max_execution_time” in the map by calling the queryOptions function. Finally, when the transaction executes the Commit, it also calls the Send function, which in turn calls the queryOptions function to update the key of ”max_execution_time“ in the map.

fatal error: concurrent map writes
goroutine 4257644 [running]:
[github.com/ClickHouse/clickhouse-go/v2.queryOptions](http://github.com/ClickHouse/clickhouse-go/v2.queryOptions)({0x2219688, 0xc0238c33e0})
        /home/test/go1.19/global/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.7.0/context.go:163](http://github.com/!click!house/clickhouse-go/v2@v2.7.0/context.go:163) +0x196
[github.com/ClickHouse/clickhouse-go/v2.(*httpConnect).readData](http://github.com/ClickHouse/clickhouse-go/v2.(*httpConnect).readData)(0xc01322e9b0, {0x2219688?, 0xc0238c33e0?}, 0xc031b80f00)
        /home/test/go1.19/global/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.7.0/conn_http.go:367](http://github.com/!click!house/clickhouse-go/v2@v2.7.0/conn_http.go:367) +0x85
[github.com/ClickHouse/clickhouse-go/v2.(*httpConnect).query.func2()](http://github.com/ClickHouse/clickhouse-go/v2.(*httpConnect).query.func2())
        /home/test/go1.19/global/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.7.0/conn_http_query.go:100](http://github.com/!click!house/clickhouse-go/v2@v2.7.0/conn_http_query.go:100) +0x8c
created by [github.com/ClickHouse/clickhouse-go/v2.(*httpConnect).query](http://github.com/ClickHouse/clickhouse-go/v2.(*httpConnect).query)
        /home/test/go1.19/global/pkg/mod/[github.com/!click!house/clickhouse-go/v2@v2.7.0/conn_http_query.go:98](http://github.com/!click!house/clickhouse-go/v2@v2.7.0/conn_http_query.go:98) +0x7ec

@CLAassistant
Copy link

CLAassistant commented Apr 25, 2024

CLA assistant check
All committers have signed the CLA.

@jkaflik jkaflik self-requested a review April 25, 2024 09:39
@jkaflik jkaflik changed the title fixed panic concurrent map wirtes Fixed panic on concurrent context key map write Apr 25, 2024
@jkaflik jkaflik merged commit ff97cb8 into ClickHouse:main Apr 25, 2024
10 checks passed
@Wang Wang deleted the fix-panic-0425 branch April 25, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants