diff mbox series

[blktests] nbd/rc: check nbd-server port readiness in _start_nbd_server()

Message ID 20240718111207.257567-1-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series [blktests] nbd/rc: check nbd-server port readiness in _start_nbd_server() | expand

Commit Message

Shinichiro Kawasaki July 18, 2024, 11:12 a.m. UTC
Recently, CKI project reported nbd/001 and nbd/002 failure with the
error message "Socket failed: Connection refused". It is suspected nbd-
server is not yet ready when nbd-client connects for the first time.

To avoid the failure, wait for the nbd-server start listening to the
port at the end of _start_nbd_server(). For that purpose, use
"nbd-client -l" command, which connects to the server and asks to list
available exports.

Reported-by: Yi Zhang <yi.zhang@redhat.com>
Link: https://github.com/osandov/blktests/issues/142
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 tests/nbd/rc | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Bart Van Assche July 18, 2024, 2:35 p.m. UTC | #1
On 7/18/24 4:12 AM, Shin'ichiro Kawasaki wrote:
> +	# Wait for nbd-server start listening the port
> +	for ((i = 0; i < 10; i++)); do
> +		if nbd-client -l localhost &> "$FULL"; then
> +			break
> +		fi
> +		sleep 1
> +	done

Has it been considered to reduce the delay from one second to e.g. a
tenth of a second and to increase the number of iterations? I do not
expect it to take one second for nbd-server to start.

Thanks,

Bart.
Shinichiro Kawasaki July 19, 2024, 5:06 a.m. UTC | #2
On Jul 18, 2024 / 07:35, Bart Van Assche wrote:
> On 7/18/24 4:12 AM, Shin'ichiro Kawasaki wrote:
> > +	# Wait for nbd-server start listening the port
> > +	for ((i = 0; i < 10; i++)); do
> > +		if nbd-client -l localhost &> "$FULL"; then
> > +			break
> > +		fi
> > +		sleep 1
> > +	done
> 
> Has it been considered to reduce the delay from one second to e.g. a
> tenth of a second and to increase the number of iterations? I do not
> expect it to take one second for nbd-server to start.

No, I did not think about it. 0.1 second wait sounds the better. Will post v2.
diff mbox series

Patch

diff --git a/tests/nbd/rc b/tests/nbd/rc
index e96dc61..a56bae5 100644
--- a/tests/nbd/rc
+++ b/tests/nbd/rc
@@ -63,13 +63,24 @@  _wait_for_nbd_disconnect() {
 }
 
 _start_nbd_server() {
+	local i
+
 	truncate -s 10G "${TMPDIR}/export"
 	cat > "${TMPDIR}/nbd.conf" << EOF
 [generic]
+allowlist=true
 [export]
 exportname=${TMPDIR}/export
 EOF
 	nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf"
+
+	# Wait for nbd-server start listening the port
+	for ((i = 0; i < 10; i++)); do
+		if nbd-client -l localhost &> "$FULL"; then
+			break
+		fi
+		sleep 1
+	done
 }
 
 _stop_nbd_server() {