Connections handling

253 views
Skip to first unread message

Krzysztof Chodak

unread,
Mar 7, 2012, 2:02:59 PM3/7/12
to rails-sqlse...@googlegroups.com
Rails 3.2.2 with remote SQL Server 2005. When I lost sight of DB (VPN down) my rails server (thin development environment) crashes. Anyone else having it?

Clifford Heath

unread,
Mar 7, 2012, 3:33:20 PM3/7/12
to rails-sqlse...@googlegroups.com
Just off the top of my head, it sounds like FreeTDS might not be rigorously checking for errors on the socket.
If this results in it writing on a socket that's been closed, it can result in a signal that will kill the app.

Try adding a catcher for SIGPIPE and see if it gets called.

Clifford Heath.

On 08/03/2012, at 6:02 AM, Krzysztof Chodak wrote:

> Rails 3.2.2 with remote SQL Server 2005. When I lost sight of DB (VPN down) my rails server (thin development environment) crashes. Anyone else having it?
>

> --
> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/rails-sqlserver-adapter/-/EGSJGo4iiHQJ.
> To post to this group, send email to rails-sqlse...@googlegroups.com.
> To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rails-sqlserver-adapter?hl=en.

Krzysztof Chodak

unread,
Mar 7, 2012, 3:36:04 PM3/7/12
to rails-sqlse...@googlegroups.com
I need to add that I am on Windows 7 32B so I guess SIGPIPE won't work for me, right?


On Wednesday, March 7, 2012 9:33:20 PM UTC+1, Clifford Heath wrote:
Just off the top of my head, it sounds like FreeTDS might not be rigorously checking for errors on the socket.
If this results in it writing on a socket that's been closed, it can result in a signal that will kill the app.

Try adding a catcher for SIGPIPE and see if it gets called.

Clifford Heath.

On 08/03/2012, at 6:02 AM, Krzysztof Chodak wrote:

> Rails 3.2.2 with remote SQL Server 2005. When I lost sight of DB (VPN down) my rails server (thin development environment) crashes. Anyone else having it?
>
> --
> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/rails-sqlserver-adapter/-/EGSJGo4iiHQJ.

> To post to this group, send email to rails-sqlserver-adapter@googlegroups.com.
> To unsubscribe from this group, send email to rails-sqlserver-adapter+unsub...@googlegroups.com.

Clifford Heath

unread,
Mar 7, 2012, 3:40:45 PM3/7/12
to rails-sqlse...@googlegroups.com
On 08/03/2012, at 7:36 AM, Krzysztof Chodak wrote:
> I need to add that I am on Windows 7 32B so I guess SIGPIPE won't work for me, right?

Ahh, probably not. But there'll likely be an equivalent thing, I forget my Windows socket programming.
Nothing likes being asked to write data on a closed socket though...

> On Wednesday, March 7, 2012 9:33:20 PM UTC+1, Clifford Heath wrote:
> Just off the top of my head, it sounds like FreeTDS might not be rigorously checking for errors on the socket.
> If this results in it writing on a socket that's been closed, it can result in a signal that will kill the app.
> Try adding a catcher for SIGPIPE and see if it gets called.
>
> Clifford Heath.
>
> On 08/03/2012, at 6:02 AM, Krzysztof Chodak wrote:
>
> > Rails 3.2.2 with remote SQL Server 2005. When I lost sight of DB (VPN down) my rails server (thin development environment) crashes. Anyone else having it?
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> > To view this discussion on the web visit https://groups.google.com/d/msg/rails-sqlserver-adapter/-/EGSJGo4iiHQJ.

> > To post to this group, send email to rails-sqlse...@googlegroups.com.
> > To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.


> > For more options, visit this group at http://groups.google.com/group/rails-sqlserver-adapter?hl=en.
>
>
>
>
>
>
>

> --
> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.

> To view this discussion on the web visit https://groups.google.com/d/msg/rails-sqlserver-adapter/-/iMiuy_txKXUJ.
> To post to this group, send email to rails-sqlse...@googlegroups.com.
> To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.

Ken Collins

unread,
Mar 7, 2012, 4:56:25 PM3/7/12
to rails-sqlse...@googlegroups.com

We have some tests in TinyTDS for this. In general we return INT_CANCEL for the server down message so we can keep on trucking.

https://github.com/rails-sqlserver/tiny_tds/blob/master/ext/tiny_tds/client.c#L57

This is supposed to compliment the adapters connection handling too by checking the state of the connection and dropping it if needed and creating a new one. Here lately I have been appending this info I recently found on the bottom of connection related issues. It covers keep alive settings and may be useful.

http://blogs.msdn.com/b/sql_protocols/archive/2006/03/09/546852.aspx

It causes good connection to break during transient network failures.
So configuring the keep-alive values too small is not recommended

Krzysztof Chodak

unread,
Mar 8, 2012, 10:42:26 AM3/8/12
to rails-sqlse...@googlegroups.com
Now I got crash due to timeout:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/tiny_tds-0.5.1-x86-mingw32/lib/tiny_tds/client.rb:68:in `connect': Adaptive Server connection timed out (TinyTds::Error)

but why it hangs whole server (now switched to thin) instead of fail to handle requests?

Krzysztof Chodak

unread,
Mar 21, 2012, 1:06:34 PM3/21/12
to rails-sqlse...@googlegroups.com
Now i got full blown ruby crash two times an hour
windbg gives me the following
Probably caused by : tiny_tds.so ( tiny_tds!Init_tiny_tds+3260f )
using tiny_tds (0.5.1 x86-mingw32)
where could I get the source to analyze?

Krzysztof Chodak

unread,
Mar 21, 2012, 2:06:18 PM3/21/12
to rails-sqlse...@googlegroups.com
Ok, found some info in  https://github.com/rails-sqlserver/tiny_tds
I will see what I can do myself

Krzysztof Chodak

unread,
Mar 21, 2012, 3:36:38 PM3/21/12
to rails-sqlse...@googlegroups.com
tiny_tds compiled
ruby still crashing (Probably caused by : tiny_tds.so ( tiny_tds!Init_tiny_tds+31ecc ))

any hints on how to get ruby_debug19 working on ruby 1.9.3p125 (2012-02-16) [i386-mingw32]?

ruby_debug.c:29:19: error: conflicting types for 'rb_iseq_compile_with_option'
C:/Ruby193/include/ruby-1.9.1/ruby-1.9.3-p125/vm_core.h:505:7: note: previous declaration of 'rb_iseq_compile_with_option' was here

was trying with
gem install ruby-debug-base19x --pre
but with no luck

Krzysztof Chodak

unread,
Mar 21, 2012, 4:43:06 PM3/21/12
to rails-sqlse...@googlegroups.com
Hmm, after reboot it builds fine
Debugger ready however it crashes too
I should expect that as it is whole ruby.exe that is crushing
What next? Anyone? As you I have gone some path alone but now i really need advise
Neem some sleep now...

Ken Collins

unread,
Mar 21, 2012, 8:54:48 PM3/21/12
to rails-sqlse...@googlegroups.com

I am not sure where I can help. Can you give me some context within running the tests in the project? Did you find my previous reply helpful? Not? In what way one or the other?

- Ken

Krzysztof Chodak

unread,
Mar 22, 2012, 6:18:20 AM3/22/12
to rails-sqlse...@googlegroups.com
tiny_tds tests are passed
I use remote 2005 sql through juniper vpn mainly issuing procedures returning more than one recordset (+ standard activerecord queries)
I can only guess that crashes are due to connectivity issues
I will try to move database to be accessed locally and see how it works then

Ken Collins

unread,
Mar 22, 2012, 10:23:04 AM3/22/12
to rails-sqlse...@googlegroups.com

OK, did you find my keep-alive info helpful? Can you follow up and let me know how/if that plays out?

- Ken

Krzysztof Chodak

unread,
Mar 22, 2012, 3:08:36 PM3/22/12
to rails-sqlse...@googlegroups.com
30 sec keep-alive was on all the time. 
I will try to catch the crash on wire using wireshark to check whether connection is alive during the crash or no.

Krzysztof Chodak

unread,
Mar 22, 2012, 4:02:41 PM3/22/12
to rails-sqlse...@googlegroups.com
Now I know what is happening on the wire: server resets the connection. The question is why?
What is strange is that there are some server responses saying that incomming packets were malformed.
Maybe it is dropping connection after defined number of malformed requestes (here 9)?
I have put pcap file (with first couple of login frames skipped) below - maybe you could have a look:
https://docs.google.com/open?id=0B8Pbr6Jr1eaCa1R0NnVfdnpUb1M4a0pVVGl3WEZTZw 
For sure there is a problem in library with handling socket resets but there could be another one with malforming requests?

Ken Collins

unread,
Mar 22, 2012, 4:11:03 PM3/22/12
to rails-sqlse...@googlegroups.com

I have no idea what a pcap file is. Have you tried looking at the FreeTDS log using DTSDUMP env var (http://www.freetds.org/userguide/logging.htm)? This could be a FreeTDS issue, but I have consistently seem them re-verify that solid base the network protocol is on. That said, a search on their forums and/or a question with logs from the dump file above would be a good way to start a conversation. If indeed there is something I can do in TinyTDS, I am all ears.

 - Ken

Krzysztof Chodak

unread,
Mar 22, 2012, 4:26:38 PM3/22/12
to rails-sqlse...@googlegroups.com
pcap file is a file containing network packets: here filtered to 1433 port traffic
wireshark is a program used for capturing but also for analyzing traffic
It should be similar to dtsdump output however it has all lower level info like socket signals (here RST) etc
I have sent inquiry to freetds mailing list
Thank you for your support

Ken Collins

unread,
Mar 22, 2012, 4:29:26 PM3/22/12
to rails-sqlse...@googlegroups.com

Cool, sorry I could not be more helpful. Your at a level that is just not in my comfort zone. I see your thread on the FreeTDS list too and will monitor it there.

- Ken

Krzysztof Chodak

unread,
Mar 23, 2012, 3:20:02 AM3/23/12
to rails-sqlse...@googlegroups.com
Why you are not comfortable? :)
I highly recommend trying wireshark - it is a very generic and
straightforward tool to debug any network related issues or trace what
the application is ever doing on the wires.
I was very surprised to see plain text password being sent using TDS
protocol. I was expecting at least a hash...

On Thu, Mar 22, 2012 at 21:29, Ken Collins <k...@metaskills.net> wrote:
>
> Cool, sorry I could not be more helpful. Your at a level that is just not in my comfort zone. I see your thread on the FreeTDS list too and will monitor it there.
>
>  - Ken
>

> --
> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.

Ken Collins

unread,
Mar 23, 2012, 7:53:20 AM3/23/12
to rails-sqlse...@googlegroups.com

FreeTDS has kerberos and SSH options for logins.

 - Ken

Krzysztof Chodak

unread,
Jul 5, 2013, 9:55:13 AM7/5/13
to rails-sqlse...@googlegroups.com
Ken, it looks like this old story already reported in freetds threat is still happening
Is it freetds bug still unresolved or what? I am keen to help to solve it somehow: got at least two application crashing from it
Reply all
Reply to author
Forward
0 new messages