Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxd-agent: Fixes intermittent exec EOF closure when vsock listener is restarted just after boot #12405

Merged
merged 2 commits into from
Oct 18, 2023

Conversation

tomponline
Copy link
Member

This PR switches the lxd-agent vsock listener to use the VMADDR_CID_ANY (4294967295) CID, rather than trying to ascertain the VM's local CID and listening only on that.

The reason is two-fold:

  1. We were seeing that sometimes the vsock.ContextID() call was returning 4294967295 just after the vsock module was loaded, but shortly afterward then started returning the correct CID assigned in QEMU. This would trigger the vsock CID change detector up to 30s later and cause the vsock listener to be restarted. Any ongoing exec operations that had started before that would be prematurely terminated. The vsock VID change detector was originally added to detect when a VM was statefully restored/migrated in such a way that its QEMU assigned CID was changed whilst the VM was running. This prevented LXD from using the lxd-agent until such time as the lxd-agent noticed its local CID had changed and restarted its listener on the new CID.

  2. However it was observed during investigating this issue that if we bound the lxd-agent listener to the VMADDR_CID_ANY (4294967295) CID then this continue to work even if the VM was statefully restored using a different CID. This is because the VMADDR_CID_ANY seems to be used as a kind of wildcard CID. The vsock manpage says:

    Consider using VMADDR_CID_ANY when binding instead of getting the local CID with
    IOCTL_VM_SOCKETS_GET_LOCAL_CID.

    There are several special addresses: VMADDR_CID_ANY (-1U) means any address for binding;

By binding to the VMADDR_CID_ANY address it also allows us to simplify the vsock listener logic and remove the vsock CID change detector entirely, neatly sidestepping the original problem.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
markylaing
markylaing previously approved these changes Oct 18, 2023
Copy link
Contributor

@markylaing markylaing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

… restarted just after boot

This PR switches the lxd-agent vsock listener to use the VMADDR_CID_ANY (4294967295) CID,
rather than trying to ascertain the VM's local CID and listening only on that.

The reason is two-fold:

 1. We were seeing that sometimes the vsock.ContextID() call was returning 4294967295 just
    after the vsock module was loaded, but shortly afterward then started returning the
    correct CID assigned in QEMU. This would trigger the vsock CID change detector up to 30s
    later and cause the vsock listener to be restarted. Any ongoing exec operations that had
    started before that would be prematurely terminated. The vsock VID change detector was
    originally added to detect when a VM was statefully restored/migrated in such a way that
    its QEMU assigned CID was changed whilst the VM was running. This prevented LXD from
    using the lxd-agent until such time as the lxd-agent noticed its local CID had changed
    and restarted its listener on the new CID.

 2. However it was observed during investigating this issue that if we bound the lxd-agent
    listener to the VMADDR_CID_ANY (4294967295) CID then this continue to work even if the VM
    was statefully restored using a different CID. This is because the VMADDR_CID_ANY seems
    to be used as a kind of wildcard CID. The vsock manpage says:

     Consider using VMADDR_CID_ANY when binding instead of getting the local CID with
     IOCTL_VM_SOCKETS_GET_LOCAL_CID.

     There are several special addresses: VMADDR_CID_ANY (-1U) means any address for binding;

By binding to the VMADDR_CID_ANY address it also allows us to simplify the vsock listener logic
and remove the vsock CID change detector entirely, neatly sidestepping the original problem.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
@tomponline
Copy link
Member Author

@markylaing please can you approve again, ta

@tomponline tomponline merged commit b0099f3 into canonical:main Oct 18, 2023
24 of 25 checks passed
@tomponline tomponline deleted the tp-vm-vsockid branch October 18, 2023 08:42
@tomponline tomponline self-assigned this Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants