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

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

Open
meetme2meat opened this issue Jan 28, 2018 · 7 comments

Comments

@meetme2meat
Copy link

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.

@headius
Copy link
Owner

headius commented Feb 1, 2018

That looks like jruby-pg was compiled against a version of JRuby that had that "RubyEncoding.newEncoding" method. I have not determined where that method came from or where it went, but it doesn't appear to exist in the jruby-9.1 branch.

We'll need to try recompiling jruby-pg against a current JRuby and see why it's using this method. I don't think it's the right thing to be calling in any case.

@meetme2meat
Copy link
Author

Thanks, @headius. I'll check the above behaviour with JRuby-9.1 branch
But .. can I do something on this?

We'll need to try recompiling jruby-pg against a current JRuby and see why it's using this method. I don't think it's the right thing to be calling in any case.

@headius
Copy link
Owner

headius commented Feb 1, 2018

You could try to build pg against a recent JRuby. I have not built it in a while and I'm suffering from jet lag so I can't help you do that tonight, but perhaps tomorrow :-)

@meetme2meat
Copy link
Author

@headius Tested this under JRuby-9.1.5.0 Same result. Other than the Encoding issue the PG client seem to block execution for an indefinite period when an exec statement is triggered by a terminating connection.

@headius
Copy link
Owner

headius commented Feb 6, 2018

@meetme2meat 9.1.5.0 is still 10 releases behind current JRuby. Are you having trouble installin 9.1.15.0?

@meetme2meat
Copy link
Author

@headius No trouble installing jruby 9.1.5.0 as such but when tested the above behaviour under 9.1.5.0 the Java::JavaLang::NoSuchMethodError error seem to persist.

Let me know If I fail to understand something your last comment.

@headius
Copy link
Owner

headius commented Mar 1, 2018

I'm sorry, you are still saying "9.1.5.0" when I am saying "9.1.15.0". Let's make this easier: please install JRuby 9.1.16.0, which is now the current release 😄

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

No branches or pull requests

2 participants