mdlayher / vsock

Package vsock provides access to Linux VM sockets (AF_VSOCK) for communication between a hypervisor and its virtual machines. MIT Licensed.
MIT License
328 stars 65 forks source link

vsock: add DialTimeout #40

Open BetaXOi opened 4 years ago

BetaXOi commented 4 years ago

We need to use Dial with timeout feature in Kata, see https://github.com/kata-containers/runtime/issues/1917#issuecomment-625069513

Signed-off-by: Ning Bo ning.bo9@zte.com.cn

BetaXOi commented 4 years ago

OK, i will try to add a new test case for timeout

BetaXOi commented 4 years ago

I have rebased and add a test for timeout. But the test case has some problems:

  1. The effective minimum timeout is DIV_ROUND_UP (tv.tv_usec, (1000000 / HZ)) see https://github.com/torvalds/linux/blob/master/net/vmw_vsock/af_vsock.c#L1571
  2. Due to the problem above, test cases sometimes will fail

[root@localhost vsock]# for i in seq 10; do go test -v -race -run TestIntegrationConnTimeout; done === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.01s) PASS ok github.com/mdlayher/vsock 0.052s === RUN TestIntegrationConnTimeout TestIntegrationConnTimeout: integration_linux_test.go:235: connect with a very short dial timeout expect ETIMEDOUT, but got --- FAIL: TestIntegrationConnTimeout (0.00s) FAIL exit status 1 FAIL github.com/mdlayher/vsock 0.032s === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.00s) PASS ok github.com/mdlayher/vsock 0.049s === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.00s) PASS ok github.com/mdlayher/vsock 0.042s === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.00s) PASS ok github.com/mdlayher/vsock 0.048s === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.00s) PASS ok github.com/mdlayher/vsock 0.046s === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.00s) PASS ok github.com/mdlayher/vsock 0.046s === RUN TestIntegrationConnTimeout TestIntegrationConnTimeout: integration_linux_test.go:235: connect with a very short dial timeout expect ETIMEDOUT, but got --- FAIL: TestIntegrationConnTimeout (0.00s) FAIL exit status 1 FAIL github.com/mdlayher/vsock 0.033s === RUN TestIntegrationConnTimeout TestIntegrationConnTimeout: integration_linux_test.go:235: connect with a very short dial timeout expect ETIMEDOUT, but got --- FAIL: TestIntegrationConnTimeout (0.00s) FAIL exit status 1 FAIL github.com/mdlayher/vsock 0.031s === RUN TestIntegrationConnTimeout --- PASS: TestIntegrationConnTimeout (0.00s) PASS ok github.com/mdlayher/vsock 0.050s [root@localhost vsock]#

mdlayher commented 3 years ago

Thank you for the PR and I apologize for the delay: I am mostly on hiatus from open source software development at the moment. However I intend to address this and the other outstanding PRs as part of #45 and will follow up once I'm able to do so. Thanks again.

mdlayher commented 2 years ago

Hi there, I apologize for the delay. With the advent of v1.0.0, perhaps it might make sense to add timeout as a parameter to the vsock.Config struct. I made the decision to share the config fields between Dial and Listen so I'd want to see if a timeout might make sense on that side too.

I'll do some investigation into what socket options are available too.

ajsinclair commented 2 years ago

I wonder if DialContext would be more flexible. It would also match the net and gRPC packages: