Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost Connections Crashing. Better dberrhandle Implementation #79

Closed
metaskills opened this issue Apr 5, 2012 · 20 comments
Closed

Lost Connections Crashing. Better dberrhandle Implementation #79

metaskills opened this issue Apr 5, 2012 · 20 comments
Milestone

Comments

@metaskills
Copy link
Contributor

Based on this James K. Lowden's excellent stack trace review.

http://lists.ibiblio.org/pipermail/freetds/2012q2/027793.html

@metaskills
Copy link
Contributor Author

It is important to read the full thread from above, the link is only the last part. Will need to QA out client.c code.

Also, this is another link on SQL Server and it's keep alive setting. Which could also play into poor connections. But the main emphasis should be on a better dberrhandle implementation.

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

@metaskills
Copy link
Contributor Author

@metaskills
Copy link
Contributor Author

This thread has some interesting keep-alive talk.
http://lists.ibiblio.org/pipermail/freetds/2012q4/028157.html

@neongrau
Copy link

neongrau commented Feb 1, 2013

Is there any way to handle these exceptions within my Rails application?
Having the problem that my thin instances are crashing hard when some Backup Tool is stopping the SQL Server at night.

@metaskills
Copy link
Contributor Author

Technically yes, read up here in the adapter. https://github.com/rails-sqlserver/activerecord-sqlserver-adapter#auto-connecting

@neongrau
Copy link

neongrau commented Feb 1, 2013

ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect returns nil
So all i need is to set it to true ?

@metaskills
Copy link
Contributor Author

No, you have to define your own methods to do what you want. These are callbacks so you can get more info and debug. As the docs say, the currently log.

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver_adapter.rb#L44-L50

So if you want to add more to that or change it, do something like this in a confi/initializers/ file.

module ActiveRecord
  module ConnectionAdapters
    class SQLServerAdapter < AbstractAdapter

      protected

      def self.did_retry_sqlserver_connection(connection,count)
        # ...
      end

      def self.did_lose_sqlserver_connection(connection)
        # ...
      end

    end
  end
end

@neongrau
Copy link

neongrau commented Feb 1, 2013

hmm, if
def self.did_retry_sqlserver_connection(connection,count)
logger.info "CONNECTION RETRY: #{connection.class.name} retry ##{count}."
end

def self.did_lose_sqlserver_connection(connection)
  logger.info "CONNECTION LOST: #{connection.class.name}"
end

is the default, shouldn't i see at least one of these messages in the log?
Because even when i turn on debug logging, i never get any of these messages. All i get is a windows popup telling me that ruby.exe has crashed. When i press "OK" then the process just ends with nothing else happening on the rails part.

And this is most i get when i run from command-line. When i run this via wrapper (with rubyw.exe) as a service that crash messages doesn't even show anywhere and the process still stays up as a zombie so noone can even tell that the service died.

@scaryguy
Copy link

scaryguy commented May 2, 2013

Is there a solution for this or not? I really have difficulty to understand. Setting

ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = true

does not work for me? At a post above you're saying that wouldn't be enough. It's not me who created this adapter who come I can fix this by my self? :|

HOW to prevent my app to die because of that kind of dead connections?? Doesn't this question have an answer? With a plain english?

@krzcho
Copy link
Contributor

krzcho commented Jul 5, 2013

Both versions 0.6.0.rc1 x86-mingw32 and 0.5.1 x86-mingw32 crash after connection is lost; no reconnection attempt, no single entry in the log
Ken: was initial dump/log investigation implemented somehow as I still see the same results: infinite loop of
dblib.c:5780:dbgetuserdata(0591C858)
dblib.c:5780:dbgetuserdata(0591C858)
dblib.c:4880:dbdead(0591C858) [alive]
dblib.c:4639:dbsqlok(0591C858)
dblib.c:4669:dbsqlok() not done, calling tds_process_tokens()
token.c:540:tds_process_tokens(05797EA8, 000939A0, 0009399C, 0x6914)
util.c:331:tdserror(05933A90, 05797EA8, 20004, 10054)
dblib.c:7929:dbperror(0591C858, 20004, 10054)
dblib.c:7981:20004: "Read from the server failed"
ending with a crash? freetds now and before is reported as 0.91 - nothing changed actually?
As I read consecutive time James K. Lowden's analysis I think it is a client problem:
"It would appear -- whether by design or not -- that the
client-installed error handler makes db-lib calls, in particular
dbsqlok(). Don't do that. It engenders infinite recursion".
My guess is that you receive SYBEWRIT (atually a SYBEREAD which is 20004 above) error before dbdead is able to return true and you are somehow trying to cancel query on a failing socket. Please move SYBEWRIT/SYBEREAD error to the same handling routine as SYBESOCK (ending connection without cancelling query) and let me test it.

@metaskills
Copy link
Contributor Author

Someone needs to provide a suggested patch to save me some time till I get a chance to look at this.

Also, I have this test that is in skip mode which would help with debugging.

@krzcho
Copy link
Contributor

krzcho commented Jul 5, 2013

I have built tiny_tds with my patch (BTW great job with the mini_portile!) and I can confirm it solves the issue: after dropping the connection (using tcpview utility from sysinternals) it is now nicely reconnecting (CONNECTION RETRY: ActiveRecord::ConnectionAdapters::SQLServerAdapter retry #0. in the log file) instead of blowing up the the process.
Patch changes handling routine only for SYBEREAD - maybe it is enough as you have some constraints for canceling a query for SYBEWRIT. Time will tell.
Please consider a fast merge/release as this issue of crashing web server could be a huge annoyance for windows users with little load applications (connection drop due to inactivity, like mine) or unstable network infrastructure.

@metaskills
Copy link
Contributor Author

Working on pushing a v0.6.0 release soon.

  • Ken

On Jul 5, 2013, at 4:32 PM, Krzysztof Chodak notifications@github.com wrote:

I have built tiny_tds with my patch (BTW great job with the mini_portile!) and I can confirm it solves the issue: after dropping the connection (using tcpview utility from sysinternals) it is now nicely reconnecting (CONNECTION RETRY: ActiveRecord::ConnectionAdapters::SQLServerAdapter retry #0. in the log file) instead of blowing up the the process.
Patch changes handling routine only for SYBEREAD - maybe it is enough as you have some constraints for canceling a query for SYBEWRIT. Time will tell.
Please consider a fast merge as this issue of crashing web server could be a huge annoyance for windows users with little load applications (connection drop due to inactivity, like mine) or unstable network infrastructure.


Reply to this email directly or view it on GitHub.

@metaskills
Copy link
Contributor Author

Closing this since issue #124 is the fix.

@jh125486
Copy link

I don't know if this a problem in TinyTds or FreeTDS or just a crappy SqlServer that is on it's last legs:
I was using TinyTds 0.5.2 as of last week, and started getting 'Something has gone wrong" when querying my sqlserver. A second or third attempt would query fine though.
I'm running the latest FreeTDS 0.91, and reading through this issue I decided to pull down the master TinyTds and upgrade to it.
It still fails at the same rate, but now I am getting: 'INT_EXIT returned for msgno 20004' .
A log of FreeTDS shows the same "db-lib is exiting because the client error handle returned INT_EXIT returned for msgno 20004".
I am unfortunately not a "windows" guy, but our windows sysads say nothing is wrong the sql server.

So I have two questions:

  1. Is the sqlserver sick?
  2. Where can I intercept these connection drops and have it manually reconnect? (I'm using Rails 3).

Thanks, this Gem has been a lifesaver btw!

@krzcho
Copy link
Contributor

krzcho commented Nov 16, 2013

Please check awl log file first
16 lis 2013 07:01 "Jacob Hochstetler" notifications@github.com napisał(a):

I don't know if this a problem in TinyTds or FreeTDS or just a crappy
SqlServer that is on it's last legs:
I was using TinyTds 0.5.2 as of last week, and started getting 'Something
has gone wrong" when querying my sqlserver. A second or third attempt would
query fine though.
I'm running the latest FreeTDS 0.91, and reading through this issue I
decided to pull down the master TinyTds and upgrade to it.
It still fails at the same rate, but now I am getting: 'INT_EXIT returned
for msgno 20004' .
A log of FreeTDS shows the same "db-lib is exiting because the client
error handle returned INT_EXIT returned for msgno 20004".
I am unfortunately not a "windows" guy, but our windows sysads say nothing
is wrong the sql server.

So I have two questions:

  1. Is the sqlserver sick?
  2. Where can I intercept these connection drops and have it manually
    reconnect? (I'm using Rails 3).

Thanks, this Gem has been a lifesaver btw!


Reply to this email directly or view it on GitHubhttps://github.com//issues/79#issuecomment-28620559
.

@krzcho
Copy link
Contributor

krzcho commented Nov 16, 2013

awl=sql
16 lis 2013 08:21 "Krzysztof Chodak" krzysztof.chodak@gmail.com
napisał(a):

Please check awl log file first
16 lis 2013 07:01 "Jacob Hochstetler" notifications@github.com
napisał(a):

I don't know if this a problem in TinyTds or FreeTDS or just a crappy
SqlServer that is on it's last legs:
I was using TinyTds 0.5.2 as of last week, and started getting 'Something
has gone wrong" when querying my sqlserver. A second or third attempt would
query fine though.
I'm running the latest FreeTDS 0.91, and reading through this issue I
decided to pull down the master TinyTds and upgrade to it.
It still fails at the same rate, but now I am getting: 'INT_EXIT returned
for msgno 20004' .
A log of FreeTDS shows the same "db-lib is exiting because the client
error handle returned INT_EXIT returned for msgno 20004".
I am unfortunately not a "windows" guy, but our windows sysads say
nothing is wrong the sql server.

So I have two questions:

  1. Is the sqlserver sick?
  2. Where can I intercept these connection drops and have it manually
    reconnect? (I'm using Rails 3).

Thanks, this Gem has been a lifesaver btw!


Reply to this email directly or view it on GitHubhttps://github.com//issues/79#issuecomment-28620559
.

@jh125486
Copy link

I'm tracking. I'll get with our support team to pour through the logs.
Thanks again.

@krzcho
Copy link
Contributor

krzcho commented Nov 16, 2013

Yes it is
16 lis 2013 08:31 "Jacob Hochstetler" notifications@github.com napisał(a):

Is this log located on the SqlServer?
Thanks!


Reply to this email directly or view it on GitHubhttps://github.com//issues/79#issuecomment-28621547
.

@metaskills
Copy link
Contributor Author

Why don't you build a gem from master and try a newer version. We have fixes around this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants