node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

can't connect to heroku db server with SSL

Open tedjt opened this issue 12 years ago • 6 comments

I'm probably doing something wrong.

I can connect to a DB hosted by Heroku from an EC2 box withpsql, but the application crashes on startup attempting to make the SSL connection to the database.

What's odd is that the application runs fine from my machine.

Error: The server does not support SSL connections
    at Socket.<anonymous> (/home/bitnami/source/server/node_modules/pg.js/lib/connection.js:70:33)
    at g (events.js:175:14)
    at EventEmitter.emit (events.js:117:20)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Readable.push (_stream_readable.js:127:10)
    at TCP.onread (net.js:526:21)

looking at the code there - the response looks like this:

< RESPONSE CODE: 51S7����~vK8Uv\w�V����`1|��#�� �#����0��0��    �v�\��-�0
<       *�H��
< 0'1%0#Uip-<redacted-IP>.ec2.internal0
< 140318000523Z
< 240315000523Z0'1%0#Uip-<redacted-IP>.ec2.internal0�"0
<       *�H��
< �0�
< ��/�6�`1�޹�JJ/�Y ��kw:%Ί��4\����"ҹ~�v��&d�>�������}Y��ZCɰ�p�{�����Z6���"$�%3d�Q���<��&|7�Ýb�sf+
< :QwC�X6�%~�����,��0���T�).��*82�SXa�w�~ا����/g��w{�l@�>Q��j�X����i��P�����������Ε�m���&۞�����!�h/�     ��SJ�a�z�)� ff�Y&~C�0
<       *�H��
< ��]��"�0LSk#k��.��L����F�]"%Z_�
< ��Ic���|��6���~ٽ�2%3n0 ���    �3��m�����R5�!M`�,�SJ��W~�cm;~+�
< LnJaL�k���`X�Hc�a
< R�x����Z{���M����{�kK;�{��|,���#.-��š�I�w6����v�)���1r�������˞l����1a��&���<�4{@�����3�~X�zj�꽎z���X�#��d�W�����XNI�� ����6k3l8
< E|��|[-����#�C��[���U��]8�4�|WC�l�3!,�*�<��)@�|��
< rֆ��)zʕٖ���
< P�F=f�]A��|��K"&���^�U�/x����F��^��UP��տ�����%")ύ;�3zs��r^&����dT�f�xM�}�B���<�g���,�l{Y�d��GHw9a�"|���Z`�9��g�N���ɠ
< �u����Ӗz ����3w��ԅ��?.�q�Ol�n��%5�0��L(�u9�����;����k͍�Zv ���k����K�����Ns�FP�)%4�2�ABsg����&��mOA�X��C!D�]���d�I��iP"��8���*��5.s��J��Γ������e>B�GW������]�NO�2�
< �t��U$�NMV'%���V0�Z���Ǖq��HsG��CK�y�b5%���]2c��K�ۊzc.�%��~5y?2�9������

tedjt avatar Mar 30 '14 03:03 tedjt

Can i see some of the code you're using to connect to postgres? Generally it's best to set PGSSLMODE=require in your environment when connecting to heroku postgres.

brianc avatar Mar 30 '14 04:03 brianc

I tried setting that environment variable, but it didn't seem to have an effect. I suspect its something to do with my environment since I've gotten it work successfully on my machine to the same database. Connection code

var options =   {
   user: config.username,
   password: config.password,
   database: config.name,
   host: config.options.host,
   port: config.options.port,
   ssl: config.options.ssl -> true
};
this.client = new pg.Client(options);
this.client.connect();

tedjt avatar Mar 30 '14 05:03 tedjt

It looks like in your code the heroku machine isn't requiring SSL when you connect to it from within ec2. Have you tried setting ssl: false when in amazon?

brianc avatar Apr 03 '14 13:04 brianc

hmm - seemed intermittent. Now I'm able to connect with the same code. Must have been something on heroku's end..

Thanks for the help!

tedjt avatar Apr 08 '14 18:04 tedjt

I know this is an old closed issue but google leads me here when I tried to solve the same problem. I noticed that the error will be raised if the heroku instance is in sleep (free tier insance), after wake it up, the error will be gone. Hope this comment can help.

junyada100 avatar Sep 11 '18 09:09 junyada100

I know this is an old closed issue but google leads me here when I tried to solve the same problem. I noticed that the error will be raised if the heroku instance is in sleep (free tier insance), after wake it up, the error will be gone. Hope this comment can help.

Is there any way to solve this problem?

sevensfive avatar Sep 17 '18 02:09 sevensfive