wasmCloud / wasmcloud-otp

wasmCloud host runtime that leverages Elixir/OTP and Rust to provide simple, secure, distributed application development using the actor model
Apache License 2.0
228 stars 48 forks source link

[BUG] Race condition: OCI caching #580

Open connorsmith256 opened 1 year ago

connorsmith256 commented 1 year ago

Describe the bug

The host has a race condition in oci.rs: on a cache miss, the host will download the parcheezy bytes and then cache them to disk. While the host is writing the bytes to disk, if a subsequent request to start the same provider is received, the host will count this as a cache hit and return the cache path. The host will then fail to start the provider, since the bytes haven't been fully written to disk yet.

To Reproduce

Note I haven't confirmed 100% this is happening, but it seems like the most likely cause. To reproduce, simply issue two provider start commands with the same OCI reference and different link names concurrently. When the race condition is triggered, you'll see this error message from the host:

"msg":"Failed to start provider wasmcloud.azurecr.io/kvredis:0.19.0 (default: \"unexpected end of file\""

Expected behavior

The host should either block subsequent provider starts until after the current request has been satisfied, or the internal NIF code should somehow block on filesystem access to the cache path...

Environment (please complete the following information)

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this has been closed too eagerly, please feel free to tag a maintainer so we can keep working on the issue. Thank you for contributing to wasmCloud!