From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with UTF8SMTPS id E1B676C207
 for <pbs-devel@lists.proxmox.com>; Fri, 29 Jan 2021 08:01:48 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with UTF8SMTP id D0C4CC188
 for <pbs-devel@lists.proxmox.com>; Fri, 29 Jan 2021 08:01:18 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with UTF8SMTPS id 21B86C178
 for <pbs-devel@lists.proxmox.com>; Fri, 29 Jan 2021 08:01:17 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with UTF8SMTP id E6B8A4570A;
 Fri, 29 Jan 2021 08:01:16 +0100 (CET)
To: Dietmar Maurer <dietmar@proxmox.com>,
 Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com>
References: <20210126101702.28778-1-d.csapak@proxmox.com>
 <898932613.1270.1611900339022@webmail.proxmox.com>
From: Dominik Csapak <d.csapak@proxmox.com>
Message-ID: <5fc24404-3cbb-71ca-a2a4-c989281b85c2@proxmox.com>
Date: Fri, 29 Jan 2021 08:01:15 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101
 Thunderbird/85.0
MIME-Version: 1.0
In-Reply-To: <898932613.1270.1611900339022@webmail.proxmox.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.244 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -0.001 Looks like a legit reply (A)
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [reader.rs, proxmox.com]
Subject: Re: [pbs-devel] [PATCH proxmox-backup v2] api2/reader: asyncify the
 reader worker task
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 29 Jan 2021 07:01:48 -0000

On 1/29/21 7:05 AM, Dietmar Maurer wrote:
> Why did you change the _guard lifetime?

how so?

before this patch the guard was moved to the 'map' closure of
the future::select call
so it did go out of scope after either future (req_fut, abort_future) 
resolved

now i moved it in the async move block of the worker, and goes out of
scope after the future resolves

the difference is the 'env.log(...)' and 'Ok(())' line, but
that should not make any difference for the guard?

> 
> 
>> On 01/26/2021 11:17 AM Dominik Csapak <d.csapak@proxmox.com> wrote:
>>
>>   
>> this way, the code is much more readable
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>> changes from v1:
>> * rebased on master
>>
>>   src/api2/reader.rs | 68 +++++++++++++++++++++-------------------------
>>   1 file changed, 31 insertions(+), 37 deletions(-)
>>
>> diff --git a/src/api2/reader.rs b/src/api2/reader.rs
>> index 43d832ce..ae936184 100644
>> --- a/src/api2/reader.rs
>> +++ b/src/api2/reader.rs
>> @@ -115,7 +115,9 @@ fn upgrade_to_backup_reader_protocol(
>>   
>>           let worker_id = format!("{}:{}/{}/{:08X}", store, backup_type, backup_id, backup_dir.backup_time());
>>   
>> -        WorkerTask::spawn("reader", Some(worker_id), auth_id.clone(), true, move |worker| {
>> +        WorkerTask::spawn("reader", Some(worker_id), auth_id.clone(), true, move |worker| async move {
>> +            let _guard = _guard;
>> +
>>               let mut env = ReaderEnvironment::new(
>>                   env_type,
>>                   auth_id,
>> @@ -130,42 +132,34 @@ fn upgrade_to_backup_reader_protocol(
>>   
>>               let service = H2Service::new(env.clone(), worker.clone(), &READER_API_ROUTER, debug);
>>   
>> -            let abort_future = worker.abort_future();
>> -
>> -            let req_fut = hyper::upgrade::on(Request::from_parts(parts, req_body))
>> -                .map_err(Error::from)
>> -                .and_then({
>> -                    let env = env.clone();
>> -                    move |conn| {
>> -                        env.debug("protocol upgrade done");
>> -
>> -                        let mut http = hyper::server::conn::Http::new();
>> -                        http.http2_only(true);
>> -                        // increase window size: todo - find optiomal size
>> -                        let window_size = 32*1024*1024; // max = (1 << 31) - 2
>> -                        http.http2_initial_stream_window_size(window_size);
>> -                        http.http2_initial_connection_window_size(window_size);
>> -                        http.http2_max_frame_size(4*1024*1024);
>> -
>> -                        http.serve_connection(conn, service)
>> -                            .map_err(Error::from)
>> -                    }
>> -                });
>> -            let abort_future = abort_future
>> -                .map(|_| -> Result<(), anyhow::Error> { Err(format_err!("task aborted")) });
>> -
>> -            use futures::future::Either;
>> -            futures::future::select(req_fut, abort_future)
>> -                .map(move |res| {
>> -                    let _guard = _guard;
>> -                    match res {
>> -                        Either::Left((Ok(_), _)) => Ok(()),
>> -                        Either::Left((Err(err), _)) => Err(err),
>> -                        Either::Right((Ok(_), _)) => Ok(()),
>> -                        Either::Right((Err(err), _)) => Err(err),
>> -                    }
>> -                })
>> -                .map_ok(move |_| env.log("reader finished successfully"))
>> +            let mut abort_future = worker.abort_future()
>> +                .map(|_| Err(format_err!("task aborted")));
>> +
>> +            let env2 = env.clone();
>> +            let req_fut = async move {
>> +                let conn = hyper::upgrade::on(Request::from_parts(parts, req_body)).await?;
>> +                env2.debug("protocol upgrade done");
>> +
>> +                let mut http = hyper::server::conn::Http::new();
>> +                http.http2_only(true);
>> +                // increase window size: todo - find optiomal size
>> +                let window_size = 32*1024*1024; // max = (1 << 31) - 2
>> +                http.http2_initial_stream_window_size(window_size);
>> +                http.http2_initial_connection_window_size(window_size);
>> +                http.http2_max_frame_size(4*1024*1024);
>> +
>> +                http.serve_connection(conn, service)
>> +                    .map_err(Error::from).await
>> +            };
>> +
>> +            futures::select!{
>> +                req = req_fut.fuse() => req?,
>> +                abort = abort_future => abort?,
>> +            };
>> +
>> +            env.log("reader finished successfully");
>> +
>> +            Ok(())
>>           })?;
>>   
>>           let response = Response::builder()
>> -- 
>> 2.20.1
>>
>>
>>
>> _______________________________________________
>> pbs-devel mailing list
>> pbs-devel@lists.proxmox.com
>> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel