P3 icon indicating copy to clipboard operation
P3 copied to clipboard

Tag reading when the database does not exist

Open pavel-krivanek opened this issue 4 years ago • 8 comments

When the database you try to connect does not exist, the method P3MessageBuffer>>#readFrom: (called from P3Client>>#readMessageOnError:) fails because the readStream next returns nil and the internal error handling does not expect such case.

pavel-krivanek avatar Apr 20 '20 12:04 pavel-krivanek

I get a clean error, instance of P3Error with message

P3Error PostgreSQL database "foo" does not exist

when I try to connect to a non existing DB

P3Client url: 'psql://sven@localhost/foo'

and then do #isWorking

svenvc avatar Apr 20 '20 12:04 svenvc

I got this error while connecting using Glorp via P3DatabaseDriver. The password is set to nil which may be part of the problem. Then the issue raises from: P3Client>>#runAuthentication, specifically from self readMessageCloseAfterError tag. The socket is closed.

pavel-krivanek avatar Apr 20 '20 13:04 pavel-krivanek

So the nil password is not really an issue, it is set correctly. I was just confused by the fact that Glorp deletes the password from the Login instance after the first usage (and it does not use discardPassword message for it)

pavel-krivanek avatar Apr 20 '20 14:04 pavel-krivanek

to reproduce in my setup, I just need to do

        connection := P3Client new.
	connection 
		host: 'localhost';
		port: 5433;
		database: 'pdmCC';
		user: 'pdm';
		password: 'somePassword'.
	connection connect

Where everything except the database name is correct.

pavel-krivanek avatar Apr 20 '20 14:04 pavel-krivanek

It is PostgreSQL 12

pavel-krivanek avatar Apr 20 '20 14:04 pavel-krivanek

I was on 11.6, now also on 12.1

P3Client new 
		host: 'localhost';
		port: 5432;
		database: 'pdmCC';
		user: 'sven';
		"password: '';"
		connect.

still gives me a clean P3Error.

Note that #readMessageCloseAfterError does a #close hence the connection will be nil (after the info is read - the dictionary is filled in correctly).

I am using https://postgresapp.com on macOS, Pharo 7.0.1 FWIW

svenvc avatar Apr 20 '20 15:04 svenvc

We are on Pharo 9.0 and Windows...

pavel-krivanek avatar Apr 21 '20 06:04 pavel-krivanek

This sometimes happens in regular use as well.

It seems that at that point the underlying socket stream is in the state 'otherEndClosedButNotThisEnd'.

It remains hard to reproduce though.

svenvc avatar May 19 '20 15:05 svenvc