关于 Cosocket 的 socket busy 报错

关于 OpenResty 的 cosocket,文档里有如下一段描述:

the cosocket object here is full-duplex, that is, a reader “light thread” and a writer “light thread” can operate on a single cosocket object simultaneously (both “light threads” must belong to the same Lua handler though, see reasons above). But you cannot have two “light threads” both reading (or writing or connecting) the same cosocket, otherwise you might get an error like “socket busy reading” when calling the methods of the cosocket object.

简单点儿说,cosocket 是全双工的,如果同一个 lua handler 有一个读线程和一个写线程的话,那么它们可以同时操作一个 cosocket 对象,但是如果两个线程一起读或者写一个 cosocket 对象的话,那么会触发「socket busy」错误。

继续阅读