question

Anne-0140 avatar image
0 Votes"
Anne-0140 asked DSPatrick edited

Host file and connection issues

We have a web service long job running overnight that failed occasionally. The error message is An existing connection was for forcibly closed by the remote host.

This web service job runs about 4-5 hrs, and most of time it is successful. Only occasionally it fails. and once it fails, we restarted it, then it succeeded without any problem. The job is
a web service from web server that connect to SQL server database that process each product, so it has many network communication back and forth between web server and database server.

We have checked if the same time, any other jobs could affect, event log, SQL error log, backup, anti-virus, data, network, there are no errors, and we also used fqdn in the web.config, no help. and since it is intermittently fail, it is hard to troubleshoot.
Our system admin suggests to add IP and FQDN name in the host file of windows. But not very clear what to add...

So should I in the web server add in the host file: C:\Windows\System32\drivers\etc\hosts
for example my webserver name is TN_MyWebServer , IP is 10. xx. xx.001 and my database server is TN_MYDBServer1 IP is 10.xx.xx.004

Shall I just add the below line in the web server host ?
10.xx. xx.001 TN_MyWebServer
10.xx. xx.001 TN_MyWebServer. mydomain.com

Currently there is nothing in the host file other than commented out examples.

Do I also need to add database server IP and FQDN in the webserver host file?
Or do I need to add database server IP and FQDN in the database server host file?


Thanks!



windows-dhcp-dns
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I will add the entire error of the job:
The error log is :
Running OvernightUpdate
Failed o: System.ServiceModel.CommunicationException: An error occurred while re
ceiving the HTTP response to http://ourserver:8086/product/BatchService.svc.
This could be due to the service endpoint binding not using the HTTP protocol. T
his could also be due to an HTTP request context being aborted by the server (po
ssibly due to the service shutting down). See server logs for more details. --->
System.Net.WebException: The underlying connection was closed: An unexpected er
ror occurred on a receive. ---> System.IO.IOException: Unable to read data from
the transport connection: An existing connection was forcibly closed by the remo
te host. ---> System.Net.Sockets.SocketException: An existing connection was for
cibly closed by the remote host
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s
ize)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s
ize)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetriev
edStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpC
hannelRequest.WaitForReply(TimeSpan timeout)

0 Votes 0 ·

Thanks Both, I also added the full error in the comment part of my original post

0 Votes 0 ·
Wools avatar image
1 Vote"
Wools answered Wools edited

It is as simple as your example shows. You can just add a line that has the IP and the host name following it (after the commented section). It essentially forces the machine to resolve that host name to that IP. I'm not sure it will fix your issue, though. It doesn't seem like it would be related to DNS.

DB Hosts File
10.xx. xx.001 TN_MyWebServer
10.xx. xx.001 TN_MyWebServer. mydomain.com

Web Server Hosts File
10.xx. xx.001 TN_MyDBServer
10.xx. xx.001 TN_MyDBServer. mydomain.com


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Wools.

Sorry just see your post.

I forgot to list SQL server IP in the orignal post, it is different server with web server. I changed in the original post as an example.

So looking above example, it seems I need to add the IP and FQDN of web server in the database server host, and add the IP mappings of database server to web server. Correct?

Thanks

0 Votes 0 ·

If the job is running from the web server, you should just do the web server. You can modify both, but modifying the database hosts file likely won't have much effect. You are correct in which mapping to use though. The mappings (IP and hostname) of the DB server should go in the web server hosts file.

1 Vote 1 ·
DSPatrick avatar image
1 Vote"
DSPatrick answered DSPatrick edited

in my this case, the job is running from the web server, shall I just add to the web server the web server IP and FQDN name mappings? Do I also need to add the database server IP into the web server host file or no need?

Add the database server name to ip in the hosts file on the problem web server. Use the same name as referenced in the web server's connection string.

If the web server also have other applications that uses different database server, it won't affect them, correct?

Should not be any effect, you can also add these name to ips as well.



--please don't forget to upvote and Accept as answer if the reply is helpful--













5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
1 Vote"
DSPatrick answered

job is running from the web server

So yes add the hosts file to this server with the name to ip's that it has connections to. This server should not need lines in there to define its own name to ip

--please don't forget to upvote and Accept as answer if the reply is helpful--






5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Anne-0140 avatar image
0 Votes"
Anne-0140 answered Wools commented

Thanks! I understand this part now quote
"You can have both lines (of your example) in there if needed and with no problems. What's important is to have a line in there as server name is referenced in the connection string."

But still not clear:

in my this case, the job is running from the web server, shall I just add to the web server the web server IP and FQDN name mappings? Do I also need to add the database server IP into the web server host file or no need?
Thanks

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I believe your system administrator is recommending you to add the database mappings to the web server hosts file. That would make the most sense.

1 Vote 1 ·

if so, just for my understanding of host file, if I added the database IP mappings to the web server host file,
If the web server also have other applications that uses different database server, it won't affect them, correct?

0 Votes 0 ·

It shouldn't affect them. The hosts file is used to force a host name to always point to the IP you add to the file. If your web server is resolving your database as a different IP than what you're adding to the host file, this would fix that. If you have other jobs running that talk to other databases/host names, it shouldn't have any effect.

1 Vote 1 ·
DSPatrick avatar image
1 Vote"
DSPatrick answered

You can have both lines (of your example) in there if needed and with no problems. What's important is to have a line in there as server name is referenced in the connection string.

Do I also need to add database server IP and FQDN in the webserver host file? Or do I need to add database server IP and FQDN in the database server host file?

add the entries in the hosts file on the server that has the problem running the "web service job"

--please don't forget to upvote and Accept as answer if the reply is helpful--




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.