Skip to content

Instantly share code, notes, and snippets.

@leucos
Created December 11, 2011 14:43
Show Gist options
  • Save leucos/1460919 to your computer and use it in GitHub Desktop.
Save leucos/1460919 to your computer and use it in GitHub Desktop.
ORA-12154 with Sequel and daemonized Thin
# Invoked with :
# thin -DR config.ru start
# (single, undetached process, oracle Ok)
# thin -DR config.ru -s2 start
# (two forked processed, oracle error ORA-12154)
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
require 'rack'
require 'init.rb'
run Utilisateurs
require 'grape'
require 'sequel'
require 'oci8'
require 'pp'
# it works in a single, undetached Thin process
# but fails with ORA-12154 when daemonized with '-s 2'
DB = Sequel.oracle('SID',
:user=>'theuser',
:password=>'thepassword')
# It always works daemonized or not with sqlite
#DB = Sequel.sqlite('./test.db')
Sequel::Model.db=DB
Sequel::Model.plugin :json_serializer
class Utilisateur < Sequel::Model
end
class Utilisateurs < Grape::API
version 'v1', :using => :header, :vendor => 'erasme', :format => :json
resource :users do
# url is : http://localhost:3000/v1/users/show/74944
pp ENV
get '/show/:id' do
Utilisateur[:id=>params[:id]]
end
end
end
>> Writing PID to tmp/pids/thin.3000.pid
Warning: NLS_LANG is not set. fallback to US-ASCII.
{"LD_LIBRARY_PATH"=>"/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib/",
...
"ORACLE_HOME"=>"/usr/lib/oracle/xe/app/oracle/product/10.2.0/client",
"USER"=>"leucos",
"USERNAME"=>"leucos",
}
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Debugging ON
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
!! Unexpected error while processing request: OCIError: ORA-12154: TNS:could not resolve the connect identifier specified
OCIError: ORA-12154: TNS:could not resolve the connect identifier specified
oci8.c:267:in oci8lib_191.so
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/adapters/oracle.rb:36:in `new'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/adapters/oracle.rb:36:in `connect'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/database/misc.rb:48:in `block in initialize'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool.rb:92:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool.rb:92:in `make_new'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:127:in `make_new'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:113:in `available'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:103:in `block in acquire'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:147:in `block in sync'
<internal:prelude>:10:in `synchronize'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:147:in `sync'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:102:in `acquire'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/connection_pool/threaded.rb:74:in `hold'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/database/connecting.rb:225:in `synchronize'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/adapters/oracle.rb:72:in `_execute'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/adapters/oracle.rb:61:in `execute'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/dataset/actions.rb:646:in `execute'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/adapters/oracle.rb:377:in `fetch_rows'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/dataset/actions.rb:131:in `each'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/dataset/actions.rb:490:in `single_record'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/dataset/actions.rb:194:in `first'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/dataset/actions.rb:33:in `[]'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/model/base.rb:1719:in `[]'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/sequel-3.30.0/lib/sequel/model/base.rb:106:in `[]'
/home/leucos/dev/ruby/oracle/laclasse-grape-issue/init.rb:26:in `block (2 levels) in <class:Utilisateurs>'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/endpoint.rb:82:in `instance_eval'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/endpoint.rb:82:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/endpoint.rb:23:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/base.rb:22:in `call!'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/base.rb:16:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/base.rb:22:in `call!'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/base.rb:16:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/error.rb:44:in `block in call!'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/error.rb:43:in `catch'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/error.rb:43:in `call!'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/middleware/base.rb:16:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/grape-0.1.5/lib/grape/api.rb:26:in `call'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/controllers/controller.rb:86:in `start'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/runner.rb:185:in `run_command'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/lib/thin/runner.rb:151:in `run!'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/gems/thin-1.3.1/bin/thin:6:in `<top (required)>'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/bin/thin:19:in `load'
/home/leucos/.rvm/gems/ruby-1.9.3-p0@oracle/bin/thin:19:in `<main>'>> Waiting for 1 connection(s) to finish, can take up to 30 sec, CTRL+C to stop now
>> Exiting!
require 'oci8'
require 'daemons'
db = OCI8.new('theuser', 'thepassword', 'SID');
db.exec('select * from utilisateurs where id = 74944') do |r|
puts r.join(',')
end
Daemonize.daemonize(File.expand_path('./log.txt'), 'test')
db = OCI8.new('theuser', 'thepassword', 'SID');
db.exec('select * from utilisateurs where id = 74944') do |r|
puts r.join(',')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment