# Gets from socket got eof (multithread)

**URL:** <https://rubytalk.org/t/gets-from-socket-got-eof-multithread/5472>\
**Category:** ruby-talk\
**Created:** [2 April 2003 03:55 UTC](https://rubytalk.org/t/gets-from-socket-got-eof-multithread/5472 "2003-04-02T03:55:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shannon\_Fang](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shannon\_Fang](https://rubytalk.org/u/Shannon_Fang)\
**Post date:** [2 April 2003 03:55 UTC](https://rubytalk.org/t/gets-from-socket-got-eof-multithread/5472/1 "2003-04-02T03:55:34Z")

</div>

Hi all,

I have a problem here. My program used a structure similar to the following:

@session=TCPSocket.new(mypopserver,110)  
while resp=@session.gets do  
blah blah  
end

It worked perfect in single user mode. While I put the code into a thread, I  
encountered problem: a lot of thread got resp=nil, and jumped out of the  
while loop.

My question is: I just connected to the socket, and everything seems fine,  
why gets return nil? why the socket reaches eof? Please note that in single  
user mode it is ok.

Thanks  
Shannon

> **···**
>
> * * *
> 
> Worried what your kids see online? Protect them better with MSN 8  
> [http://join.msn.com/?page=features/parental&pgmarket=en-gb&XAPID=186&DI=1059](http://join.msn.com/?page=features/parental&pgmarket=en-gb&XAPID=186&DI=1059)

---

<div class="post-metadata">

**Author:** ![Kero](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kero](https://rubytalk.org/u/Kero)\
**Post date:** [2 April 2003 21:53 UTC](https://rubytalk.org/t/gets-from-socket-got-eof-multithread/5472/2 "2003-04-02T21:53:08Z")

</div>

> @session=TCPSocket.new(mypopserver,110)  
> while resp=@session.gets do  
> blah blah  
> end
> 
> It worked perfect in single user mode. While I put the code into a thread, I  
> encountered problem: a lot of thread got resp=nil, and jumped out of the  
> while loop.

You’ll have to tell a bit more. how many sockets do you open? and how many  
threads? I don’t want to know what Ruby does when those two numbers are  
unequal…

Bye,  
Kero.

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [5 April 2003 02:41 UTC](https://rubytalk.org/t/gets-from-socket-got-eof-multithread/5472/3 "2003-04-05T02:41:47Z")

</div>

Hi,

As usual I need information about your platform, your Ruby version,  
and preferably error reproducing script. I couldn’t reproduce similar  
error using 1.8.0 2003-03-28.

> **···**
>
> In message “gets from socket got eof (multithread)” on 03/04/02, “Shannon Fang” [xrfang@hotmail.com](mailto:xrfang@hotmail.com) writes:
> 
> > Hi all,
> > 
> > I have a problem here. My program used a structure similar to the following:
> > 
> > @session=TCPSocket.new(mypopserver,110)  
> > while resp=@session.gets do  
> > blah blah  
> > end
> > 
> > It worked perfect in single user mode. While I put the code into a thread, I  
> > encountered problem: a lot of thread got resp=nil, and jumped out of the  
> > while loop.
> > 
> > My question is: I just connected to the socket, and everything seems fine,  
> > why gets return nil? why the socket reaches eof? Please note that in single  
> > user mode it is ok.
> 
> It might caused by your stdio behavior.
> 
> ```
> matz.
> 
> ```
