Skip to content

Commit 0c0111f

Browse files
authored
Merge pull request #290 from NordSecurity/msz/FILE-550-paused-event-not-emited-for-the-receiver-when-meshnet-is-toggled-quickly-on-the-sender-side
Ensure there is no race condition in events
2 parents 8d02230 + 8bb4864 commit 0c0111f

File tree

5 files changed

+118
-7
lines changed

5 files changed

+118
-7
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Add `connection_retries` config parameter
99
* Add `TransferDeffered` event indicating the connection to peer couldn't be establish at this time
1010
* Disallow downloading file for which any path component is larger than 250 characters
11+
* Fix ocassional missing of `TransferPaused` event when toggling libdrop on and off quickly
1112

1213
---
1314
<br>

drop-transfer/src/manager.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ impl TransferManager {
131131
drop(conn)
132132
}
133133
_ => {
134+
if let Some(conn) = &state.conn {
135+
if !conn.is_closed() {
136+
anyhow::bail!("The transfer connection is in progress already");
137+
}
138+
}
139+
134140
info!(self.logger, "Issuing pending requests for: {}", xfer.id());
135141
state.issue_pending_requests(&conn, &self.logger);
136142
state.conn = Some(conn);

test/drop_test/action.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,22 @@ def __str__(self):
404404
class WaitAndIgnoreExcept(Action):
405405
def __init__(self, events: typing.List[Event]):
406406
self._events: typing.List[Event] = events
407-
self._found: typing.List[Event] = []
408407

409408
async def run(self, drop: ffi.Drop):
410409
fuse = 0
411410
limit = 100
411+
found = []
412412

413413
while True:
414414
e = await drop._events.wait_for_any_event(100, ignore_progress=True)
415415

416416
if e in self._events:
417-
if e in self._found:
417+
if e in found:
418418
raise Exception(f"Event {e} was received twice")
419419

420-
self._found.append(e)
420+
found.append(e)
421421

422-
if len(self._found) == len(self._events):
422+
if len(found) == len(self._events):
423423
break
424424
else:
425425
continue

test/drop_test/event.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def __str__(self):
303303

304304

305305
class ChecksumStarted(Event):
306-
def __init__(self, uuid_slot: int, file: str, size: int):
306+
def __init__(self, uuid_slot: int, file: str, size: typing.Optional[int] = None):
307307
self._uuid_slot = uuid_slot
308308
self._file = file
309309
self._size = size
@@ -315,8 +315,9 @@ def __eq__(self, rhs):
315315
return False
316316
if self._file != rhs._file:
317317
return False
318-
if self._size != rhs._size:
319-
return False
318+
if self._size is not None and rhs._size is not None:
319+
if self._size != rhs._size:
320+
return False
320321

321322
return True
322323

test/scenarios.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11535,4 +11535,107 @@
1153511535
),
1153611536
},
1153711537
),
11538+
Scenario(
11539+
"scenario52",
11540+
"Repeatedly stop and start transfer, except paused events to be present all the time",
11541+
{
11542+
"DROP_PEER_REN": ActionList(
11543+
[
11544+
action.ConfigureNetwork(rate="4mbit"),
11545+
action.Start("DROP_PEER_REN"),
11546+
action.WaitForAnotherPeer("DROP_PEER_STIMPY"),
11547+
action.NewTransfer("DROP_PEER_STIMPY", ["/tmp/testfile-big"]),
11548+
action.Wait(
11549+
event.Queued(
11550+
0,
11551+
"DROP_PEER_STIMPY",
11552+
{
11553+
event.File(
11554+
FILES["testfile-big"].id, "testfile-big", 10485760
11555+
),
11556+
},
11557+
)
11558+
),
11559+
action.Repeated(
11560+
[
11561+
action.WaitAndIgnoreExcept(
11562+
[event.Paused(0, FILES["testfile-big"].id)]
11563+
),
11564+
action.Sleep(0.3),
11565+
action.NetworkRefresh(),
11566+
],
11567+
times=40,
11568+
),
11569+
action.WaitAndIgnoreExcept(
11570+
[event.FinishFileUploaded(0, FILES["testfile-big"].id)]
11571+
),
11572+
action.ExpectCancel([0], True),
11573+
action.NoEvent(),
11574+
action.Stop(),
11575+
]
11576+
),
11577+
"DROP_PEER_STIMPY": ActionList(
11578+
[
11579+
action.ConfigureNetwork(rate="4mbit"),
11580+
action.Start(
11581+
"DROP_PEER_STIMPY",
11582+
dbpath="/tmp/db/50-stimpy.sqlite",
11583+
),
11584+
action.Wait(
11585+
event.Receive(
11586+
0,
11587+
"DROP_PEER_REN",
11588+
{
11589+
event.File(
11590+
FILES["testfile-big"].id, "testfile-big", 10485760
11591+
),
11592+
},
11593+
)
11594+
),
11595+
action.Download(
11596+
0,
11597+
FILES["testfile-big"].id,
11598+
"/tmp/received/50",
11599+
),
11600+
action.Repeated(
11601+
[
11602+
action.WaitForOneOf(
11603+
[
11604+
event.Start(0, FILES["testfile-big"].id, None),
11605+
event.ChecksumStarted(0, FILES["testfile-big"].id),
11606+
]
11607+
),
11608+
action.Stop(),
11609+
action.WaitAndIgnoreExcept(
11610+
[event.Paused(0, FILES["testfile-big"].id)]
11611+
),
11612+
action.Start(
11613+
"DROP_PEER_STIMPY",
11614+
dbpath="/tmp/db/50-stimpy.sqlite",
11615+
),
11616+
],
11617+
times=40,
11618+
),
11619+
action.WaitAndIgnoreExcept(
11620+
[
11621+
event.FinishFileDownloaded(
11622+
0,
11623+
FILES["testfile-big"].id,
11624+
"/tmp/received/50/testfile-big",
11625+
)
11626+
]
11627+
),
11628+
action.CheckDownloadedFiles(
11629+
[
11630+
action.File("/tmp/received/50/testfile-big", 10485760),
11631+
],
11632+
),
11633+
action.CancelTransferRequest([0]),
11634+
action.ExpectCancel([0], False),
11635+
action.NoEvent(),
11636+
action.Stop(),
11637+
]
11638+
),
11639+
},
11640+
),
1153811641
]

0 commit comments

Comments
 (0)