1

I was trying to import server_info api in the ibm_db extension. It worked well in windows but in Linux, it returns tread sleep error.

#<Thread:0x000055c9febc5ca0 sleep> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
stack level too deep (SystemStackError)
^C*** stack smashing detected ***: <unknown> terminated

code:-

require 'ibm_db'
conn = IBM_DB.connect('DATABASE=;HOSTNAME=localhost;PORT=50000;PROTOCOL=TCPIP;UID=;PWD=','','')
puts 'this is ibm_db'
#Thread.report_on_exception = false
puts 'this is begin'
puts IBM_DB
serverinfo = IBM_DB::server_info( conn )
puts serverinfo.DBMS_NAME[0,100]
puts IBM_DB.close(conn)

why the same code returns the error in Linux but woe=rks well in windows.

When I run the code in debug mode it does not produce any error only in normal mode it produces an error.

Thanks, Akhil

akhil
  • 105
  • 10
  • Although I have not setup same code on my machine. In my opinion, In debug mode your code works fine due to time "DB connection is established" and then you go next. In case of code run, before db connection is established it goes next and produces error because connection is not established. It's not related to windows/linux. It's related to establish connection time out – Chitresh goyal Jan 30 '20 at 11:38
  • @Chitreshgoyal so what you say is to increase the connection time? – akhil Jan 31 '20 at 05:37
  • well, two things we can try. 1. sleep for 5-10 second 2. check db connection like: p "connected" if ActiveRecord::Base.connected? --- in your case need to check in ibm_db gem how to check if it's connected or not--- still if you face same issue I will setup same on my machine. – Chitresh goyal Jan 31 '20 at 07:07
  • 1
    Hi @Chitreshgoyal Thanks for the help!!!! after adding sleep for 5 seconds it worked may I know the reason why It got worked after add sleep and what changes I have to do in the gem so that it can work without adding sleep function also. – akhil Feb 03 '20 at 07:42
  • https://github.com/ibmdb/ruby-ibmdb/blob/master/IBM_DB_Adapter/ibm_db/ext/ibm_db.c#L688 Is this right wy to call the C functions? – akhil Feb 03 '20 at 13:01
  • You don't need to make any change in gem. It is just you need to search gem configuration. If db connection is established then move forward else wait/error/exception. for example: connState = ibm_db.active(conn) print(connState) – Chitresh goyal Feb 04 '20 at 09:11

1 Answers1

0

Well, two approach

  1. use sleep for 5-10 second after db connection
  2. check db connection like: p "connected" if ActiveRecord::Base.connected?

In your case, need to check in ibm_db gem how to check if connection established or not

conn=ibm_db.connect("DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password",'','')
connState = ibm_db.active(conn)
print(connState)

if it says "TRUE" go ahead else pause/sleep whatever your requirement.

Chitresh goyal
  • 313
  • 1
  • 7