Skip to content

Commit 377fa01

Browse files
committed
Report imex and configure success/failure after freeing ongoing
Otherwise it's possible that library user (e.g. test) tries to start another ongoing process when previous one is not freed yet.
1 parent 7ce291f commit 377fa01

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- python: avoid exceptions when messages/contacts/chats are compared with `None`
1313
- node: wait for the event loop to stop before destroying contexts #3431
1414
- emit configuration errors via event on failure #3433
15+
- report configure and imex success/failure after freeing ongoing process #3442
1516

1617
### API-Changes
1718
- python: added `Message.get_status_updates()` #3416

src/configure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ impl Context {
7575
}))
7676
.await;
7777

78+
self.free_ongoing().await;
79+
7880
if let Err(err) = res.as_ref() {
7981
progress!(
8082
self,
@@ -93,8 +95,6 @@ impl Context {
9395
progress!(self, 1000);
9496
}
9597

96-
self.free_ongoing().await;
97-
9898
res
9999
}
100100

src/imex.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,24 @@ pub async fn imex(
8686
) -> Result<()> {
8787
let cancel = context.alloc_ongoing().await?;
8888

89-
let res = async {
90-
let success = imex_inner(context, what, path, passphrase).await;
91-
match success {
92-
Ok(()) => {
93-
info!(context, "IMEX successfully completed");
94-
context.emit_event(EventType::ImexProgress(1000));
95-
Ok(())
96-
}
97-
Err(err) => {
98-
// We are using Anyhow's .context() and to show the inner error, too, we need the {:#}:
99-
error!(context, "{:#}", err);
100-
context.emit_event(EventType::ImexProgress(0));
101-
bail!("IMEX FAILED to complete: {}", err);
102-
}
103-
}
104-
}
105-
.race(async {
106-
cancel.recv().await.ok();
107-
Err(format_err!("canceled"))
108-
})
109-
.await;
89+
let res = imex_inner(context, what, path, passphrase)
90+
.race(async {
91+
cancel.recv().await.ok();
92+
Err(format_err!("canceled"))
93+
})
94+
.await;
11095

11196
context.free_ongoing().await;
11297

98+
if let Err(err) = res.as_ref() {
99+
// We are using Anyhow's .context() and to show the inner error, too, we need the {:#}:
100+
error!(context, "IMEX failed to complete: {:#}", err);
101+
context.emit_event(EventType::ImexProgress(0));
102+
} else {
103+
info!(context, "IMEX successfully completed");
104+
context.emit_event(EventType::ImexProgress(1000));
105+
}
106+
113107
res
114108
}
115109

0 commit comments

Comments
 (0)