client: clear Inserting state before connect in ResetConnection#516
client: clear Inserting state before connect in ResetConnection#516iliaal wants to merge 1 commit into
Conversation
ResetConnection() connects first, then clears the inserting state. When the reconnect throws, the state stays Inserting. The destructor then calls EndInsert() on the old dirty socket. Move the clear to the first line.
f964a9b to
480e754
Compare
|
Hi, @iliaal, The line above When this happens during a reconnect (in Could you please explain your use case? I can't really see a situation in which moving this line earlier would be beneficial. |
|
Use case: a user-initiated You're right that this weakens the strong exception guarantee of
If you'd rather keep |
|
I see the problem now. That makes sense. However, the issue is that inserts in ClickHouse are not transactional. If you insert a small dataset, it may appear as though resetting the connection without calling As a result, you can never rely on resetting the connection and omitting |
|
Agreed: inserts aren't transactional, and I'm not treating skip-EndInsert as a rollback. Whatever the server already flushed stays flushed; that's its at-least-once behavior and outside the client's control. The fix doesn't depend on that. The defect is narrower. After a user calls
So the guarantee is "don't complete the insert handshake for an insert the user abandoned," not "atomic rollback." If you'd rather keep |
ResetConnection() connects first, then clears the inserting state.
When the reconnect throws (max_connections, port exhaustion, DNS blip, etc.), the state stays Inserting. The destructor then calls EndInsert() on the old dirty socket and commits whatever the caller had in flight.
Move state_ = State::Idle to the first line, before any connect. A failed reconnect now safely prevents the implicit EndInsert.