News for hackers. Stuff that matters.
Re:Unix System Call Timeouts by loeg on Sunday March 12, 2017 @10:17PM (#13854744)
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?

Re:Unix System Call Timeouts by TheDong on Sunday March 12, 2017 @10:30PM (#13854799)
> 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.

Re:Unix System Call Timeouts by loeg on Sunday March 12, 2017 @10:39PM (#13854851)
> 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.

Re:Unix System Call Timeouts by spc476 on Sunday March 12, 2017 @10:56PM (#13854923)
As if. At $WORK, we service requests (millions per day) that require access to NFS mounted files [1]. A network hiccup could effect one request but not another. I'm not sure how a "whole-application watchdog" would work for us.

As it is, the main thread will schedule a "wakeup" from another thread whose sole existence is to interrupt file system calls stuck in NFS. Yes, it would be nice if such code didn't have to exist. But it does.

On the plus side, it's there for a feature that isn't used that often. On the bad side, it's there for a feature that isn't used that often.

[1] Like most such decisions, it was a political decision [2] rather than a technical decision.

[2] Strippers and steak, baby! Strippers and steak! And those responsible are not bound by their decisions. We lowly engineers are.

Re:Unix System Call Timeouts by xenadu02 on Sunday March 12, 2017 @10:51PM (#13854904)
I'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.

Re:Unix System Call Timeouts by fulafel on Monday March 13, 2017 @01:51AM (#13855529)
NFS violates a number of basic Unix filesystem guarantees. It's well documented that it violates POSIX guaranteed filesystem semantics. The abstraction NFS chose is "filesystem operations don't time out", and implements this by just making your process hang as long as the network is dead - possibly forever.

I'm not sure it's a bad thing that the Unix FS API doesn't do networked filesystems. Everbody is using userspace APIs for remote file access, and the big and varied design space of remote file access semantics doesn't get bottlenecked on 30 year old system call APIs.

Re:Unix System Call Timeouts by loeg on Sunday March 12, 2017 @11:22PM (#13855007)
> 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?

Re:Unix System Call Timeouts by xenadu02 on Monday March 13, 2017 @02:39AM (#13855702)
> You understand that's still offensive and implies I have brain damage, right?

My apologize, I didn't intend that. I mean that some people are used to Unix and use their familiarity as a post-hoc rationalization for some of the poorly designed aspects of it.

To be clear: my position is that several Unix APIs are bad designs. Rather than making excuses for them we should demand better cross-platform APIs.

> It doesn't have to be bespoke, but I agree that the Unix VFS interface isn't appropriate for it.

I don't agree. Network filesystems should be mountable and traversable just like local filesystems, but the OS and libraries should do more to be async and multi-thread aware, as should applications.

Re:Unix System Call Timeouts by pjmlp on Monday March 13, 2017 @11:12AM (#13858435)
> Rather than making excuses for them we should demand better cross-platform APIs.

We already have them in the form of language runtimes.

POSIX as cross-platform API is mostly relevant to C.

Even C++ is moving beyond POSIX, by providing proper OS abstractions on the standard library.

Re:Unix System Call Timeouts by fiddlerwoaroof on Monday March 13, 2017 @01:10AM (#13855376)
I suspect old systems like Multics did.

But, this is the sort of thing that Richard Gabriel is talking about in worse is better[1]

[1]: https://www.dreamsongs.com/WorseIsBetter.html

Re:Unix System Call Timeouts by slrz on Monday March 13, 2017 @03:10PM (#13861249)
> The Unix IO model isn't well designed and is far from the only Unix-ism to work poorly in the face of threads

Right, threads in the form of pthreads should've never been introduced into Unix, as they made a huge mess of many interfaces.

The rfork "you have processes that can share resources" model is a much better fit (although it doesn't solve all problems). It's what Linux as well as FreeBSD implement at the kernel level anyway except they add tons of ugly stuff on top of it to allow for performant implementations of POSIX threads semantics.

Re:Unix System Call Timeouts by geofft on Sunday March 12, 2017 @11:09PM (#13854959)
> NFS basically assumes a reliable network. Operations should complete more or less immediately.

I don't know what you mean by this; are you claiming that NFS' design, by nature of being part of the kernel VFS, only makes sense in a reliable network because it pretends to work like a local filesystem? Then yes, we're discussing ways to fix that.

But if you're claiming NFS only works in reliable networks, that's absolutely untrue. NFSv3, at least, is designed to work in unreliable networks by being stateless (dare I say RESTful) and having well-defined semantics for operations that may not have completed. Close-to-open consistency is a way of sacrificing consistency for availability. And so forth. I've used it in production on remarkably unreliable networks and it absolutely works. But, of course, you need the application to be aware that it's using a filesystem that will expose the network's unreliability.

By "unreliable network" I mean a real-world network. I'm not suggesting NFS-over-wifi where you're expecting some sort of moshfs, I'm talking about inter-data-center WAN links, LAN links that occasionally get congested, etc.

> Filesystem bugs are filesystem bugs -- the application layer shouldn't have to work around them.

Shouldn't have to, no. But with the UNIX API, it doesn't even have the option of doing so. And being liberal in what you accept from others is a good way to build robust systems; this continues to apply when "you" is userspace and "others" is kernelspace.

For instance, a specific type of application, maybe a high-concurrency web server, might want to add timeouts on filesystem operations that can interrupt the current request and raise a 500 or something, but not abort the entire server. We have exactly this problem with https://lost-contact.mit.edu, a web server that quite intentionally provides access to all public AFS content via the web. It's running normal Apache on top of the normal OpenAFS client. Sometimes a remote AFS server maintained by someone else will go unresponsive, and eventually all threads on the entire Apache server will hang, one-by-one, making requests to the stuck server. There's no way to solve this in the UNIX design; we'd have to write a userspace AFS client to make this work.

Re:Unix System Call Timeouts by AstralStorm on Monday March 13, 2017 @03:42AM (#13855928)
Not true, you can set up an alarm signal to interrupt most syscalls. All fs ones at least.
Re:Unix System Call Timeouts by geofft on Monday March 13, 2017 @09:16AM (#13857500)
Not when you're using many network filesystems. From man 5 nfs:

"The intr / nointr mount option is deprecated after kernel 2.6.25. Only SIGKILL can interrupt a pending NFS operation on these kernels, and if specified, this mount option is ignored to provide backwards compatibility with older kernels."

I'm curious if you've used a network filesystem in production - this feels like such an everyday occurrence with either NFS or AFS that I'm surprised to hear people claim that it works differently.

Re:Unix System Call Timeouts by TheDong on Sunday March 12, 2017 @10:52PM (#13854909)
> How is a syscall-level timeout more useful than a whole-application watchdog for handling flaky mounted filesystems?

It's more useful because once you enter into a syscall, it's out of the application's control.

The kernel's off in its happy place doing whatever it does, and the application has no control over that other than being able to specify timeouts to begin with or having async epoll-like interfaces.

Re:Unix System Call Timeouts by AstralStorm on Monday March 13, 2017 @03:41AM (#13855917)
You can also interrupt syscalls using signals or pthread_cancel.
Re:Unix System Call Timeouts by ec109685 on Monday March 13, 2017 @12:28AM (#13855230)
s/application/thread/
Re:Unix System Call Timeouts by GauntletWizard on Sunday March 12, 2017 @10:38PM (#13854848)
In 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.

Re:Unix System Call Timeouts by loeg on Sunday March 12, 2017 @10:40PM (#13854857)
> 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.

Re:Unix System Call Timeouts by xelxebar on Monday March 13, 2017 @12:40AM (#13855270)
Exactly. 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.
Re:Unix System Call Timeouts by GauntletWizard on Tuesday March 14, 2017 @05:00PM (#13871425)
Re:Unix System Call Timeouts by tyingq on Sunday March 12, 2017 @10:29PM (#13854794)
I 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.

Re:Unix System Call Timeouts by bonzini on Monday March 13, 2017 @02:04AM (#13855581)
If 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.
Re:Unix System Call Timeouts by loeg on Sunday March 12, 2017 @10:39PM (#13854854)
There's nothing elegant about unreliable NFS in general. :-)
Re:Unix System Call Timeouts by AstralStorm on Monday March 13, 2017 @03:38AM (#13855903)
Wait is a poor interface anyway, waitpid is always superior and supports a timeout.
Re:Unix System Call Timeouts by skarap on Monday March 13, 2017 @03:04AM (#13855779)
And what about unlink()? Should it have a timeout? How would one use it?