Skip to content

Terminating a connection result in Encoding error and indefinite block statement. #38

@meetme2meat

Description

@meetme2meat

The issue is related to pg_jruby (0.17.1 java) Tested with JRuby 9.0.5.0 and ...

java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Terminating the Postgres connection result in (encoding) error type different from the one obtained in ruby pg.(first time).

Re-Running the SQL statement on already terminated connection result in indefinite blocking again a behaviour much different from ruby pg.

Ruby PG behaviour

 require 'pg'
 conn = PG.connect(dbname: 'postgres', user: 'postgres')
 ## Use either `pg_terminate_backend` or `kill` command to terminate the connection.
 conn.exec('select 1') ## 1 st time
 PG::UnableToSend: erver closed the connection unexpectedly
 	This probably means the server terminated abnormally
 	before or while processing the request.
 
 conn.exec('select 1`) ## 2nd time same error type no blocking.
 PG::UnableToSend: no connection to the server
 

Jruby pg behaviour

require 'pg'
conn = PG.connect(dbname: 'postgres', user: 'postgres')
## Use either `pg_terminate_backend` or `kill` command to terminate the connection.
conn.exec('select 1') ## 1 st time
Java::JavaLang::NoSuchMethodError: org.jruby.RubyEncoding.newEncoding(Lorg/jruby/Ruby;Lorg/jcodings/Encoding;)Lorg/jruby/RubyEncoding;
	from org.jruby.pg.Connection.newPgErrorCommon(Connection.java:1434)
	from org.jruby.pg.Connection.newPgError(Connection.java:1450)
	from org.jruby.pg.Connection.exec(Connection.java:544)
	from org.jruby.pg.Connection$INVOKER$i$0$2$exec_DBG.call(Connection$INVOKER$i$0$2$exec_DBG.gen)
	from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:201)
	from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:197)
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:313)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
	from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:316)
	from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:77)
	from org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:122)
	from org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:177)
	from org.jruby.ir.interpreter.Interpreter.evalWithBinding(Interpreter.java:202)
	from org.jruby.RubyKernel.evalCommon(RubyKernel.java:1009)
	from org.jruby.RubyKernel.eval19(RubyKernel.java:976)
	from org.jruby.RubyKernel$INVOKER$s$0$3$eval19_DBG.call(RubyKernel$INVOKER$s$0$3$eval19_DBG.gen)
... 104 levels...
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:313)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
	from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:316)
	from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:77)
	from org.jruby.ir.interpreter.Interpreter.INTERPRET_ROOT(Interpreter.java:112)
	from org.jruby.ir.interpreter.Interpreter.execute(Interpreter.java:99)
	from org.jruby.ir.interpreter.Interpreter.execute(Interpreter.java:35)
	from org.jruby.ir.IRTranslator.execute(IRTranslator.java:42)
	from org.jruby.Ruby.runInterpreter(Ruby.java:848)
	from org.jruby.Ruby.runInterpreter(Ruby.java:853)
	from org.jruby.Ruby.runNormally(Ruby.java:752)
	from org.jruby.Ruby.runFromMain(Ruby.java:569)
	from org.jruby.Main.doRunFromMain(Main.java:415)
	from org.jruby.Main.internalRun(Main.java:310)
	from org.jruby.Main.run(Main.java:239)
	from org.jruby.Main.main(Main.java:201)

Running the SQL statement 2nd time result indefinite block of the running program.

conn.execute('select 1')
## the code block no timeout happens.

If the connection is closed by the client then the JRuby pg End result is same as Ruby pg.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions