# How to build a daemon

**URL:** <https://www.ruby-forum.com/t/how-to-build-a-daemon/56224>\
**Category:** Ruby\
**Created:** [March 29, 2006, 11:34am UTC](https://www.ruby-forum.com/t/how-to-build-a-daemon/56224 "2006-03-29T11:34:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominik\_Werder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@Dominik\_Werder](https://www.ruby-forum.com/u/Dominik_Werder)\
**Post date:** [March 29, 2006, 11:34am UTC](https://www.ruby-forum.com/t/how-to-build-a-daemon/56224/1 "2006-03-29T11:34:28Z")

</div>

Hello!

While building a little network daemon I stumbled upon the following  
issue:

I have no idea how much data I can read without blocking. So an attacker  
could simply ignore the protocol and stop the transfer so that my daemon  
blocks forever…  
How do you avoid this simple issue? The only method I found is setting a  
Timeout::timeout 10 do end around the code, but this requires the  
timeout module and I don’t know if this works reliable…

Could anybody please give me a hint? Thank you!

bye!  
Dominik

---

<div class="post-metadata">

**Author:** ![Dominik\_Werder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@Dominik\_Werder](https://www.ruby-forum.com/u/Dominik_Werder)\
**Post date:** [March 29, 2006, 11:54am UTC](https://www.ruby-forum.com/t/how-to-build-a-daemon/56224/2 "2006-03-29T11:54:41Z")

</div>

Dominik Werder wrote:

> Hello!
> 
> While building a little network daemon I stumbled upon the following issue:
> 
> I have no idea how much data I can read without blocking. So an attacker  
> could simply ignore the protocol and stop the transfer so that my daemon  
> blocks forever…  
> How do you avoid this simple issue? The only method I found is setting a  
> Timeout::timeout 10 do end around the code, but this requires the  
> timeout module and I don’t know if this works reliable…

You’d typically have a thread that handles a connection. So the worst  
case is that a single thread blocks om IO but this does not block the  
whole process. You’re only out of luck if Ruby is stuck in some long  
running call into an external C lib (can be a system call or whatever)  
because it doesn’t support native threads (yet).

Kind regards

```
robert
```
