Skip to content

Commit 495ae7b

Browse files
authored
fix: fix CancelRow() causing data corruption if called after send exception (#44)
1 parent 0525be1 commit 495ae7b

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/net-questdb-client-tests/HttpTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,33 @@ public async Task CancelLine()
993993
Assert.That(srv.PrintBuffer(), Is.EqualTo(expected));
994994
}
995995

996+
997+
[Test]
998+
public async Task CancelLineAfterClear()
999+
{
1000+
using var srv = new DummyHttpServer();
1001+
await srv.StartAsync(HttpPort);
1002+
using var sender = Sender.New($"http::addr={Host}:{HttpPort};auto_flush=off;");
1003+
1004+
sender.Table("good");
1005+
sender.Symbol("asdf", "sdfad");
1006+
sender.Column("ddd", 123);
1007+
sender.At(new DateTime(1970, 1, 2));
1008+
1009+
sender.Table("bad");
1010+
sender.Symbol("asdf", "sdfad");
1011+
sender.Column("asdf", 123);
1012+
sender.Clear();
1013+
sender.CancelRow();
1014+
1015+
sender.Table("good");
1016+
await sender.AtAsync(new DateTime(1970, 1, 2));
1017+
await sender.SendAsync();
1018+
1019+
var expected = "good 86400000000000\n";
1020+
Assert.That(srv.PrintBuffer(), Is.EqualTo(expected));
1021+
}
1022+
9961023
[Test]
9971024
public async Task CannotConnect()
9981025
{

src/net-questdb-client/Buffers/BufferV1.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ public void Clear()
135135
_buffers[i] = (_buffers[i].Buffer, 0);
136136
}
137137

138-
Position = 0;
139-
RowCount = 0;
140-
Length = 0;
141-
WithinTransaction = false;
142-
_currentTableName = "";
138+
Position = 0;
139+
RowCount = 0;
140+
Length = 0;
141+
WithinTransaction = false;
142+
_currentTableName = "";
143+
_lineStartBufferIndex = 0;
144+
_lineStartBufferPosition = 0;
143145
}
144146

145147
/// <inheritdoc />

0 commit comments

Comments
 (0)