arthurnn / memcached

A Ruby interface to the libmemcached C client
Academic Free License v3.0
432 stars 127 forks source link

Patch libmemcached to handle EINTR in poll(2) #204

Closed casperisfine closed 3 years ago

casperisfine commented 3 years ago

There was two places where libmemcached uses poll but doesn't handle EINTR.

One was on the connect path, the other in the non-blocking IO read path.

I applied a similar path to both, basically unlimited retry as long as poll fail with errno == EINTR.

I wrote two tests relying on StackProf, to make sure they are close to reality.

casperisfine commented 3 years ago

We tested this in production, it works as expected.

It's far from perfect because on EINTR the timeout duration is basically reset, but that's not something that should happen much in practice except during profiling, so not really a concern.