crete-dev
crete-dev copied to clipboard
Ensure vm-node to crete-run port file is not reused
Scenario:
- vm-node starts the VM image
- The VM silently fails
- vm-node writes the port to file that the VM is expected to use
- vm-node waits indefinitely for crete-run to connect (also a separate issue)
- vm-node is restarted manually
- crete-run reads the old port file when the VM starts before vm-node has written a new one
Solution:
A fix should be simple. Just ensure the port file is removed before the VM image is started. This could be done in VMNodeFSM's ctor (or equivalent). A more robust solution is to follow the core guidelines R.1.
The present implementation is lacking sufficient resource (i.e., the port file) management:
// ...write port_file...
server->open_connection_wait();
fs::remove(port_file_path);
Clearly, this is inadequate. If open_connection_wait() throws, or vm-node is terminated between these two invocations, fs::remove() is not invoked, thus causing the same problem.