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

Instance: Set receive timeout for LXC command client sock #11293

Closed
wants to merge 1 commit into from

Conversation

mihalicyn
Copy link
Member

@mihalicyn mihalicyn commented Jan 17, 2023

Issue #4257

Signed-off-by: Alexander Mikhalitsyn aleksandr.mikhalitsyn@canonical.com

Please see lxc/lxc#4257

@mihalicyn
Copy link
Member Author

mihalicyn commented Jan 17, 2023

We may want to use liblxc.HasAPIExtension(extension) to detect if set timeout is supported or not. Let's decide.

lxc/go-lxc#166
lxc/lxc#4260

@@ -632,6 +632,12 @@ func (d *lxc) initLXC(config bool) error {
return err
}

// To discuss: take defalt timeout value from some global config?
err = liblxc.SetTimeout(time.Duration(10) * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to make it configurable.
However what happens if we, say, set a 10s timeout by default on init, as you're doing here, will this affect a longer timeout passed to d.c.Shutdown()?

Copy link
Member

Choose a reason for hiding this comment

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

Also, can se set the timeout on the cc returned from liblxc.NewContainer rather than on the library as a whole?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, can se set the timeout on the cc returned from liblxc.NewContainer rather than on the library as a whole?

sure, it's just mistake. Thanks!

Copy link
Member Author

@mihalicyn mihalicyn Jan 18, 2023

Choose a reason for hiding this comment

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

I don't think we need to make it configurable. However what happens if we, say, set a 10s timeout by default on init, as you're doing here, will this affect a longer timeout passed to d.c.Shutdown()?

Yep, that's what I've said in the original issue. That's why right now this timeout is not applied to all commands. We will need to extend liblxc and each command one by one to support this timeout. [like this commit ] And I'm not sure that we really need that. So, it's thing to discuss.

Copy link
Member

Choose a reason for hiding this comment

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

OK so right now this would just record the timeout value but not use it, and then you would extend each underlying call to use it. And we wouldn't need to update d.c.Shutdown() to use it because it already has its own timeout support?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now, for Shutdown this container-wide timeout will be ignored at all.

You want to propose to take this "container-wide timeout" as a default value for Shutdown call (if timeout specified as -1)?

Copy link
Member

Choose a reason for hiding this comment

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

well in Go at least we cannot specify -1, but we could have it use the container wide timeout if the timeout passed was zero perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an interesting point.

What we have in the liblxc:

	/*!
	 * \brief Request the container shutdown by sending it \c
	 * SIGPWR.
	 *
	 * \param c Container.
	 * \param timeout Seconds to wait before returning false.
	 *  (-1 to wait forever, 0 to avoid waiting).
	 *
	 * \return \c true if the container was shutdown successfully, else \c false.
	 */
	bool (*shutdown)(struct lxc_container *c, int timeout);

In the go-lxc:

// Shutdown shuts down the container.
func (c *Container) Shutdown(timeout time.Duration) error {
	c.mu.Lock()
	defer c.mu.Unlock()

	if c.container == nil {
		return ErrNotDefined
	}

	if err := c.makeSure(isRunning); err != nil {
		return err
	}

	if !bool(C.go_lxc_shutdown(c.container, C.int(timeout.Seconds()))) {
		return ErrShutdownFailed
	}
	return nil
}

I don't think that it would be correct to change semantics of liblxc shutdown call. But we can change go-lxc's Shutdown implementation to take the "container-wide timeout" as a default in case when timeout is 0. Or, better, to add another method like ShutdownWithTimeout.

Copy link
Member

Choose a reason for hiding this comment

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

We don't need ShutdownWithTimeout as we already have Shutdown(timeout time.Duration).

I propose we just ignore the container wide timeout for the Shutdown(timeout time.Duration) function then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I propose we just ignore the container wide timeout for the Shutdown(timeout time.Duration) function then.

It's just the current implementation behavior.

Issue canonical#4257

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
@tomponline
Copy link
Member

@mihalicyn happy to close this for now?

@mihalicyn
Copy link
Member Author

@mihalicyn happy to close this for now?

why close? We don't want to take it?

@tomponline
Copy link
Member

Oh right, you never requested a subsequent review on it and the RFC subject suggested this was just a design proposal.

So does liblxc support this now?

@tomponline
Copy link
Member

tomponline commented Jan 23, 2023

static analysis tests are failing, suggesting not.

Error: lxd/cgo.go:14:8: could not import C (cgo preprocessing failed) (typecheck)
import "C"
       ^
Error: lxd/instance/drivers/driver_lxc.go:636:11: cc.SetTimeout undefined (type *lxc.Container has no field or method SetTimeout) (typecheck)
	err = cc.SetTimeout(time.Duration(10) * time.Second)
	         ^
make: *** [Makefile:267: static-analysis] Error 1
Error: Process completed with exit code 2.

@tomponline
Copy link
Member

And jenkins is red across the board with compile errors:

https://jenkins.linuxcontainers.org/job/lxd-github-pull-test/8656/

lxd/instance/drivers/driver_lxc.go:636:11: cc.SetTimeout undefined (type *lxc.Container has no field or method SetTimeout)

@tomponline
Copy link
Member

I thought you would open a working PR once the changes had been made to liblxc itself.

@mihalicyn
Copy link
Member Author

I've posted PRs to all projects https://github.com/lxc/lxd/pull/11293#issuecomment-1385870390

@tomponline
Copy link
Member

OK I missed that. The "RFC" in the title has really confused me as thought it was just a proposal and not ready yet.
If its ready for review lets drop the "RFC" bit.

@tomponline tomponline changed the title [RFC] driver_lxc: set receive timeout for LXC command client sock Instance: Set receive timeout for LXC command client sock Jan 23, 2023
@mihalicyn
Copy link
Member Author

Oh right, you never requested a subsequent review on it and the RFC subject suggested this was just a design proposal.

That's it. But I've started from implementing that in liblxc, go-lxc, lxd. It's easier to discuss when everything is almost ready :)

So does liblxc support this now?

lxc/lxc#4260

@tomponline
Copy link
Member

This helps with the weekly news letter too as the PR titles show up in there.

@tomponline
Copy link
Member

tomponline commented Jan 23, 2023

We may want to use liblxc.HasAPIExtension(extension) to detect if set timeout is supported or not. Let's decide.

On this point, what happens in go-lxc if we call the timeout and the underlying liblxc doesn't support the extension?
If nothing happens, then I don't see a need to use HasAPIExtension and we can just always set the timeout and then it only gets applied if liblxc supports it.

What do you think?

Or are you thinking that an error should be returned if liblxc doesn't support it and thus we should check HasAPIExtension before calling it?

@@ -632,6 +632,12 @@ func (d *lxc) initLXC(config bool) error {
return err
}

// To discuss: take defalt timeout value from some global config?
Copy link
Member

Choose a reason for hiding this comment

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

Lets take this comment out now the PR is ready for review.

@mihalicyn
Copy link
Member Author

On this point, what happens in go-lxc if we call the timeout and the underlying liblxc doesn't support the extension?

Right now, SetTimeout from go-lxc should return an error.

Or are you thinking that an error should be returned if liblxc doesn't support it and thus we should check HasAPIExtension before calling it?

Yep, we can just use error code to detect that operation is not supported EOPNOTSUPP or we can use HasAPIExtension. It's a matter of taste.

@tomponline
Copy link
Member

I see. I'm happy with either, but detecting the error seems simpler. Thanks

@stgraber stgraber marked this pull request as draft January 25, 2023 04:41
@stgraber
Copy link
Contributor

Moving to Draft until the liblxc and go-lxc side of this is finalized.

@tomponline
Copy link
Member

@mihalicyn happy to close this until its ready?

@mihalicyn mihalicyn closed this Feb 16, 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.

None yet

3 participants