3 ms·
Yeah, wait() doesn't have a standard way to wait for a timeout. I would wait (with timeout) for the SIGCHLD with some OS-dependent interface (signalfd+poll/sel
by loeg 10y ago
Yeah, wait() doesn't have a standard way to wait for a timeout. I would wait (with timeout) for the SIGCHLD with some OS-dependent interface (signalfd+poll/select/epoll on Linux, or kevent on BSD).
But: What possible semantics could you want for mkdir() such that a timeout is sane?
- tyingq 10y agoI would guess the poster is just lamenting the lack of a straightforward solution. Assume you're doing a mkdir() on an nfs mounted volume. It could hang, for quite some time. You would like to set a timeout and error out. There are no terrific solutions. There are workarounds, yes...but largely inelegant.
- loeg 10y agoThere's nothing elegant about unreliable NFS in general. :-)
- bonzini 10y agoIf you set a timeout on NFS operations, you could get an error and yet the mkdir could have succeeded---it could be the response that was delayed. This is really hard to handle, and that's the reason why NFS 's "soft" mount option is considered unsafe.
- TheDong 10y ago> But: What possible semantics could you want for mkdir() such that a timeout is sane? nfs is mentioned a few lines later. Creating directories on any sort of network mount can and will time out, and it's better if your application can handle that sort of error rather than just wait forever. Yes, the error can't conclusively say "the directory wasn't actually created", but at least it can say "it might not have been, dunno" FUSE filesystems also can have bugs resulting in mkdir hanging forever. Neither of those are all that insane.
- loeg 10y ago> nfs is mentioned a few lines later. Creating directories on any sort of network mount can and will time out NFS basically assumes a reliable network. Operations should complete more or less immediately. How is a syscall-level timeout more useful than a whole-application watchdog for handling flaky mounted filesystems? If you want a flaky network filesystem, I think it's probably better to go with some application-level protocol rather than putting it below Unix's filesystem interface. > FUSE filesystems also can have bugs resulting in mkdir hanging forever. Filesystem bugs are filesystem bugs -- the application layer shouldn't have to work around them.
- xenadu02 10y agoI'm not picking on you specifically but when people say things like "Unix gives you brain damage" this is what they mean. Your suggestion is that the network should be reliable (a strict impossibility) or that every application should use a bespoke protocol to do simple things like working with a network file system. The Unix IO model isn't well designed and is far from the only Unix-ism to work poorly in the face of threads (signals and fork/exec are common offenders; not even memcpy is safe in a signal handler!) This is hardly surprising: it was slapped together ad-hoc over the years.
- loeg 10y ago> I'm not picking on you specifically but when people say things like "Unix gives you brain damage" this is what they mean. You understand that's still offensive and implies I have brain damage, right? > every application should use a bespoke protocol to do simple things like working with a network file system. It doesn't have to be bespoke, but I agree that the Unix VFS interface isn't appropriate for it. What operating system are you aware of that provides a mkdir interface with timeout? Windows' CreateDirectory() does not. OS X is just BSD. We're departing the realm of mainstream systems. QNX mkdir does not appear to take a timeout. Plan9 uses create() with a DIR flag, which does not take a timeout. Help me out here?
- 10y ago
- GauntletWizard 10y agoIn a distributed systems problem, almost everything should have a timeout - mkdir and all filesystem operations should be prepared for the possibility that backing store will be slow, unresponsive, or simply broken. On the other hand, the application layer is probably the wrong place to implement such. Most NFS clients have the option to set a timeout, and system calls that take longer than it instead receive EIO. This isn't perfect, but if you're building an application that needs more complex behavior than that, you probably do need to be building on a more filesystem specific API. Still, there's a point to be made here - There should be a general template or recommendation for what that API is.
- loeg 10y ago> On the other hand, the application layer is probably the wrong place to implement such. Most NFS clients have the option to set a timeout, and system calls that take longer than it instead receive EIO. This isn't perfect, but if you're building an application that needs more complex behavior than that, you probably do need to be building on a more filesystem specific API. Yes, exactly.
- xelxebar 10y agoExactly. I'm kind of surprised to see the comments arguing that all potentially blocking syscalls should have a timeout field or something. That kind of thing just begs to be factored out into a more general framework.
- GauntletWizard 10y agoSomething similar: https://golang.org/pkg/context/ https://golang.org/pkg/context/
- skarap 10y agoAnd what about unlink()? Should it have a timeout? How would one use it?
- AstralStorm 10y agoWait is a poor interface anyway, waitpid is always superior and supports a timeout.