I am writing an app which listens tcp connection (see this example) . When a tcp connection disconnected I got error read tcp ip_server.:port1->ip_client:port2: wsarecv: An existing connection was forcibly closed by the remote host.
I expected error EOF and timeout(for conn.SetReadDeadline()) and tried to catch error with this code:
if err != nil {
log.Println("getting error from listener")
// I thought, listener can continue work another cases
if neterr, ok := err.(net.Error); ok && neterr.Timeout() || err == io.EOF {
log.Println("Closing connection...")
break // connection will be closed
}
}
Anyone knows about this error? Do you know how to catch this error and when this error will occured ? Thanks in advance !
The usual cause of this error is that you sent data over a connection which had already been closed by the peer. In other words, an application protocol error.
Related
I am trying to setup a websocket server as described in this boost beast example.
Everything works fine except that the websocket stream read throw unexpeced system error with error code of "End of file" and "Operation cancelled"
beast::flat_buffer buffer;
try {
ws->read(buffer); // ws is in the free store
}
catch(beast::system_error const& se) {
if(se.code() == websocket::error::closed) {
LOG_INFO << "ws closed, exiting handing thread..";
break;
}
LOG_WARNING << "exception: " << se.code() << ", " << se.code().message();
}
After client connected to this server, and the server start to read incoming msg from the client with
ws->read(buffer);
From time to time, one End of file system_error and many operation cancelled system error are caught and printed as below:
WARNING exception: asio.misc:2, End of file
WARNING exception: system:125, Operation canceled
WARNING exception: system:125, Operation canceled
WARNING exception: system:125, Operation canceled
I googled around, End of file is probably caused by underlying tcp socket is closed, but the issue is that the disconnct happens very often and that does not make sense. And what exactly will cause Operation cancelled system error?
It turns out to be caused by bad netowrk. When I disable some VPN, the issue is gone.
I am using custom build for NodeMCU with following modules: cjson, file, gpio, http, net, node, ow, tmr, websocket, wifi.
conn = nil
conn=net.createConnection(net.TCP) -- 30 seconds timeout time of serv
conn:on("connection", function(conn, payload)
print("Server DB Connected, sending event") -- This line is not getting print on esplorer.
conn:send ( <some-data>)
end)
conn:connect(80,"mysite.com")
conn:close()
For debugging i tried using following code :
net.dns.resolve("www.google.com", function(sk, ip)
if (ip == nil) then
print("DNS fail!")
else
print("Resolved: " .. ip)
end
end)
But above is giving output " DNS fail! "
Site is working perfectly fine along with server.
A normal GET request to the same site using putty is returning correct data.
Please help me resolving the issue.
I have an ESP12 with NodeMCU firmware installed (modules: http, tls, etc.).
Whenever I try to use http.get with an https link, I receive the following error:
> http.get("https://pastebin.com/raw/cAB83eF1", nil, function(code, data)
>> if (code < 0) then
>> print("HTTP request failed")
>> else
>> print(code, data)
>> end
>> end)
> HTTP client: Disconnected with error: -114
HTTP client: Connection timeout
HTTP client: Connection timeout
where as when I tried the same pastebin.com link without https, I am able to receive data and the HTTP status code.
> http.get("http://pastebin.com/raw/cAB83eF1", nil, function(code, data)
>> if (code < 0) then
>> print("HTTP request failed")
>> else
>> print(code, data)
>> end
>> end)
> 200 test
Quoting from the docs of http.get:
Each request method takes a callback which is invoked when the
response has been received from the server. The first argument is the
status code, which is either a regular HTTP status code, or -1 to
denote a DNS, connection or out-of-memory failure, or a timeout
(currently at 10 seconds).
Since the docs say valid codes are -1 and HTTP codes, how can I find out what is -114?
Edit1: After building the firmware with debug option ON. I get the following error:
> http.get("https://pastebin.com/raw/cAB83eF1", nil, function(code, data)
>> if (code < 0) then
>> print("HTTP request failed")
>> else
>> print(code, data)
>> end
>> end)
> client handshake start.
please start sntp first !
please start sntp first !
client handshake failed!
Reason:[-0x7200]
HTTP client: Disconnected with error: -114
HTTP client: Connection timeout
HTTP client: Connection timeout
=rtctime.get()
1501394767 272709
>
As per the log statement Reason:[-0x7200] 0x72 hex is -114 decimal which gets printed later Disconnected with error: -114.
Also sntp.sync() has already been performed as seen from the output of rtctime.get(). Even if the SNTP has been synced why is the message please start sntp first ! printed?
Also later in the log, after the -114 message, it displays Connection timeout message. How can I change the timeout for https connections? any pointers to C/header files?
Note: I do have the git repo and docker image installed on my Linux machine for building the firmware.
PS: I need https because I'll be making my ESP12 communicate with a RESP API hosted on the cloud.
This is a short and unsatisfactory answer: you hit https://github.com/nodemcu/nodemcu-firmware/issues/1707.
Got an EndpointWriter error:
14/10/30 23:12:29 ERROR EndpointWriter: AssociationError [akka.tcp://sparkWorker#node001:35249] -> [akka.tcp://sparkExecutor#node001:7088]: Error [Association failed with [akka.tcp://sparkExecutor#node001:7088]] [
akka.remote.EndpointAssociationException: Association failed with [akka.tcp://sparkExecutor#node001:7088]
Caused by: akka.remote.transport.netty.NettyTransport$$anonfun$associate$1$$anon$2: Connection refused: node001/10.69.144.56:7088
the node001 and 10.69.144.56 are both the node itself. my understanding is that akka was trying to connect to a port in local but got rejected. The executor port was fixed to be '7087'.
Thanks for your help!
The usual reason for connection refused is that there is nothing listening on the port. If the port that executor is listening on is 7087, akka is trying to make a connection to port 7088 and there's probably nothing listening there. Check your code or configuration to see if you got 7088 instead of 7087.
I am trying to connect to a SFTP remote server using JSCH library version 0.1.49. Every time I run the program I receive the following error :
Initializing...
Connection to SFTP server is successfully
com.jcraft.jsch.JSchException: Unable to connect to SFTP server.com.jcraft.jsch.JSchException: failed to send channel request
at shell.MainClass.JschConnect(MainClass.java:95)
at shell.MainClass.main(MainClass.java:30)
line 30 is : sftpChannel.connect() from the code below :
System.out.println("Initializing...");
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession(ProjectConstants.rmUsername,ProjectConstants.rmHost, 22);
session.setPassword(ProjectConstants.rmPassword);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
if (session.isConnected() == true) {
System.out.println("Connection to SFTP server is successfully");
}
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
try {
sftpChannel.connect();
} catch (Exception e) {
throw new JSchException("Unable to connect to SFTP server. "
+ e.toString());
}
the credentials I am using are correct ( it connects through FileZilla using the same data ), and I also disabled the proxy for that server ( either way I get the same error with or without proxy )
If anyone could help me I would greatly appreciate it as I am stuck with this error for about a week now ...
Thank you.
Check if SFTP server is started and running.
I had encountered the same issue - I was not able to open SFTP channel to my server, but I could connect with WinSCP. It took me some time to notice that WinSCP would fallback to SCP hence confusing me. Starting the server solved this issue.
Check Subsystem sftp /usr/lib/openssh/sftp-server in /etc/ssh/sshd_config
In /etc/ssh/sshd_config I changed:
Subsystem sftp /usr/lib/openssh/sftp-server
to:
Subsystem sftp internal-sftp
It helps.