0

I'm testing my application which requests some data from database. In case when the database is DOWN and installed on localhost I'm getting immediate Connection refused but when the database is running on remote machine Connection timeout happens. What could be the difference? I'm using apache BasicDataSource to get a connection.

sys463
  • 337
  • 2
  • 5
  • 18

1 Answers1

1

Connection refused means service is not available at all. Refer to What can be the reasons of connection refused errors? post.

While Connection timeout is a time period within which a connection between a client and a server must be established. If not established for some reason your code throws this exception after some retries. https://itstillworks.com/server-connection-timeout-mean-22703.html could give you some insights.

localhost Vs remote:

on remote machine the machine is acting as a proxy i.e. the machine is running but underlying service is not accessible via the network. While on localhost say localhost:port is down connection is straight away refused and no attempt of wait for connection is done.(Though if your machine had been up with the service but connection establishing was unsuccessful you would have got timeout )

Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
  • Thanks for your answer @Vinay Prajapati! But I still cannot get why errors are different in a similar cases? Code is the same, both instances of database are the same and are similarly DOWN. The question is more "why do I get different errors when connecting to database on a localhost and on remote machine when both of them are DOWN?" – sys463 Nov 07 '19 at 07:36
  • 1
    It has nothing to do with local and remote specifically. Most probably it has to do with a firewall not opening the port. – user207421 Nov 07 '19 at 07:49