-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: query flight rpc connection leaking (#13956)
* fix: create FlightReceiver using current rt * fix: use notify_one in Flightreceiver::close instead of `notify_waiters`, so that the task spawned in `streaming_receiver` shall not missed the notification, even if the notification is sent before waiting * add some comments about the notification receiving * more comment * adjust comment * introduce WatchNotify * lint * resolve conflict * wip * Revert "fix: create FlightReceiver using current rt" This reverts commit 6a0dbe6. * cleanup * add ut for WatchNotify * move WatchNotify to common/base
- Loading branch information
1 parent
b86311a
commit e76a65e
Showing
9 changed files
with
107 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use tokio::sync::watch; | ||
|
||
/// A Notify based on tokio::sync::watch, | ||
/// which allows `notify_waiters` to be called before `notified` was called, | ||
/// without losing notification. | ||
pub struct WatchNotify { | ||
rx: watch::Receiver<bool>, | ||
tx: watch::Sender<bool>, | ||
} | ||
|
||
impl Default for WatchNotify { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl WatchNotify { | ||
pub fn new() -> Self { | ||
let (tx, rx) = watch::channel(false); | ||
Self { rx, tx } | ||
} | ||
|
||
pub async fn notified(&self) { | ||
let mut rx = self.rx.clone(); | ||
// we do care about the result, | ||
// any change or error should wake up the waiting task | ||
let _ = rx.changed().await; | ||
} | ||
|
||
pub fn notify_waiters(&self) { | ||
let _ = self.tx.send_replace(true); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn test_notify() { | ||
let notify = WatchNotify::new(); | ||
let notified = notify.notified(); | ||
notify.notify_waiters(); | ||
notified.await; | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_notify_waiters_ahead() { | ||
let notify = WatchNotify::new(); | ||
// notify_waiters ahead of notified being instantiated and awaited | ||
notify.notify_waiters(); | ||
|
||
// this should not await indefinitely | ||
let notified = notify.notified(); | ||
notified.await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters