hawkw/sharded-slab

fall back gracefully when max thread IDs are reached

hawkw opened this issue ยท 2 comments

hawkw commented

When the thread ID limit defined by the Config is reached, we currently panic. This isn't great.

As I said in tokio-rs/tracing#1485:

I do think sharded-slab could handle this better. We could potentially reserve the last thread ID (in this case, 4096) for a special shard that allows concurrent mutation by multiple threads, with a mutex, and use that as a fallback when the thread ID cap is reached. That way, rather than panicking, we'd degrade to contending a mutex for threads over the max, which might be a better solution. However, that would be a bit of work to implement...but I'll open a ticket for it upstream.

I'm guessing this is the cause of a panic at the following line:

let shard = self.shards[idx].load(Relaxed).unwrap_or_else(|| {
?

If anything, replacing that [idx] with .get(idx).expect("too many threads") would already be quite helpful when debugging ๐Ÿ™‚

hawkw commented

I'm guessing this is the cause of a panic at the following line:

let shard = self.shards[idx].load(Relaxed).unwrap_or_else(|| {
?

If anything, replacing that [idx] with .get(idx).expect("too many threads") would already be quite helpful when debugging ๐Ÿ™‚

Yeah, that's a good point; we should at least make the panic message a bit more helpful in that case (and perhaps include what the configured thread count is).

I'd happily merge a PR that makes this change, if you're interested in opening one? Otherwise, I'll try to improve it when I get the chance.