I use MailKit to send messages, app runs on Win 10.
I wrote my Mailservice, and my project used this service to send infos, warnings or fault notifications to me.
In the case that more messages should be sent within a short periode (loop ?), I get the error 'Too many connections open .."
Ok. I used 'Await' to await the end of each step and so I await the end of the disconnect-operation.
How can I get too many open connections?
Private Shared Async Function TransmitMail(mail As MimeMessage) As Task(Of Boolean)
Try
Using client = New SmtpClient()
With client
Await .ConnectAsync(Host, 587, False)
Await .AuthenticateAsync(UserName, Password)
Await .SendAsync(mail)
Await .DisconnectAsync(True)
Threading.Thread.Sleep(5000) <<<<--
End With |
End Using |
Return True |
``` |
After adding a explicite sleep of about 5 seconds, the problem is gone.
Any explaination?
Thanks for helping.
With best regards
Gerhard
Just because you closed and cleaned up the socket on the local machine doesn't mean that the server has had a chance to close and cleanup the socket at the remote end.
Related
I am trying to send error reports from an application using a local send-only Postfix server. The server works fine (I have tested it using both telnet and mail) but I can't get the code below to work:
Properties props = new Properties();
props.put("mail.smtp.host",host); // "localhost"
props.put("mail.smtp.port",port); // "25"
props.put("mail.smtp.auth",auth); // false
props.put("mail.smtp.starttls.enable",tls); // false
props.put("mail.smtp.ssl.enable",ssl); // false
props.put("mail.smtp.sendpartial",true);
Session session = Session.getDefaultInstance(props);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
msg.setSubject(subject);
msg.setContent(content,"text/plain");
Transport.send(msg);
I have traced it up to the final call to send(), and it just hangs at that point -- it never returns from the call.
If I set "mail.smtp.auth" to true and replace the call to Transport.send() with this code:
Transport transport = s.getTransport("smtp");
transport.connect(host,Integer.parseInt(port,10),"foo","bar");
transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));
transport.close();
then it hangs inside the call to connect(). The same as true if I set "mail.smtp.auth" to false and set the username and password to null in the call to connect().
In /var/log/mail.log I see this:
connect from localhost[127.0.0.1]
and after I kill the hung process:
lost connection after CONNECT from localhost[127.0.0.1]
disconnect from localhost[127.0.0.1] commands=0/0
Can anyone see what I've done wrong here?
The problem turned out to be that the user "postfix" was being blocked by iptables. Adding an ACCEPT rule for postfix solved the problem.
I made a Azure cloud service which download files from a FTP server and then upload them to an Azure storage.
When I debug my service, everything works fine, the files are uploaded to the storage. Once I published the service, I received an error (not always, but 4 times of 5 try):
"System.Net.WebException: The operation has timed out."
The line number of the error correspond to the line
Dim response As FtpWebResponse = CType(request.GetResponse, FtpWebResponse)
Why does it work on local debug and not from cloud ?
For information, there is no proxy or what. It seems to work in a random way.
A part of my code :
'Request
Dim request As FtpWebRequest = CType(WebRequest.Create(Configuration.Address + suffixPath), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.DownloadFile
'Login and pwd
request.Credentials = New NetworkCredential(Configuration.Login, Configuration.Password)
request.UsePassive = False
request.KeepAlive = True
request.Timeout = Integer.MaxValue
request.ReadWriteTimeout = Integer.MaxValue
Try
Dim response As FtpWebResponse = CType(request.GetResponse, FtpWebResponse)
Dim stream As Stream = response.GetResponseStream
...
Thx all
--- EDIT ----
I found this article :
http://feedback.azure.com/forums/217313-networking-dns-traffic-manager-vpn-vnet/suggestions/3346609-icmp-support-for-azure-websites-roles-cloud-serv
It's a suggestion to add ICMP traffic for Azure VMs, Services...
I tried to do a simple ping test from my Azure Cloud Service to my FTP Server, with a Timeout of 30 seconds, I received ... a timeout error immediatly.
Do you think guys that is a possible explanation of my problem ?
If it does, is there any means to download file from ftp by passing thru UDP or something else ?
I Finally found the solution to my problem.
The restriction for ICMP traffic inside a Azure VM or Service was the thing.
So, I simply used a WebClient object to download my files.
Dim webclient As New WebClient
webclient.Credentials = New NetworkCredential(login, password)
Dim bytesData As Byte() = webclient.DownloadData(addressOfFTPServer + fileNameToDownload)
Return bytesData
Hope this will help.
I have this https://gist.github.com/ohcibi/5418898 Gist which is basically just the example from the sinatra-websocket github page and a bit of Redis code pasted in. The part
settings.redis.subscribe 'foobar' do |on|
on.message do |channel, message|
settings.sockets.each do |s|
s.send message
end
end
end
is blocking the Sinatra app to boot properly aus subscribe is blocking. I made small success by putting the subscription inside the ws.onopen handler but this would override the subscription for every new websocket (i.e. only the newest websocket will receive the message).
How to do it to be able to notify all connected sockets when a new redis message is incoming?
I was successful by putting it in another Thread and using Thread locals for the sockets:
set(:watcher, Thread.new do
redis = Redis.new
Thread.current['sockets'] = []
redis.subscribe 'foobar' do |on|
on.message do |channel, message|
Thread.current['sockets'].each do |s|
s.send message
end
end
end
end)
I then do
settings.watcher['sockets'] << ws
instead of
settings.sockets << ws
and
settings.redis.publish 'foobar', msg
to notify the sockets via the redis watcher.
See the updated gist: https://gist.github.com/ohcibi/5418898
Whenever I try and make any Twitter request, my application always hangs. This does not apply to the oAuthUtility though, I have successfully authorized the user to use my application, but whenever I make a request it just hangs. Here is one of the requests I am making that hangs:
Dim response As TwitterResponse(Of TwitterStatus) = TwitterStatus.Update(myFire_tokens.Tokens, TextBox1.Text)
If response.Result <> RequestResult.Success Then
MessageBox.Show(response.ErrorMessage, "Error", MessageBoxButton.OK)
Else
MessageBox.Show("Tweet Sent", "Awesome!", MessageBoxButton.OK)
End If
This hang occurs on Version 2.4, and releases: 504, 516, and 523. On Silverlight 5 and 4. The problem I belive lies with TwitterResponse because the method does get called (For example if I ran the above code, the tweet would post) because I can see a OK response in Fiddler.
No exceptions are thrown in the debugger, the application just hangs.
You should link against the SilverlightAsync project.
If you are on the Silverlight-side, it would have used this signature:
public static IAsyncResult Update(
OAuthTokens tokens,
string text,
StatusUpdateOptions options,
TimeSpan timeout,
Action<TwitterAsyncResponse<TwitterStatus>> function)
notice the additional two parameters?
Your code should look something like this
TwitterStatus.Update(
myFire_tokens.Tokens,
TextBox1.Text,
Nothing,
0,
Sub (response As TwitterAsyncResponse<TwitterStatus>)
If response.Result <> RequestResult.Success Then
MessageBox.Show(response.ErrorMessage, "Error", MessageBoxButton.OK)
Else
MessageBox.Show("Tweet Sent", "Awesome!", MessageBoxButton.OK)
End If
End Sub)
When using https.request with node.js v04.7, I get the following error:
Error: socket hang up
at CleartextStream.<anonymous> (http.js:1272:45)
at CleartextStream.emit (events.js:61:17)
at Array.<anonymous> (tls.js:617:22)
at EventEmitter._tickCallback (node.js:126:26)
Simplified code that will generate the error:
var https = require('https')
, fs = require('fs')
var options = {
host: 'localhost'
, port: 8000
, key: fs.readFileSync('../../test-key.pem')
, cert: fs.readFileSync('../../test-cert.pem')
}
// Set up server and start listening
https.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end('success')
}).listen(options.port, options.host)
// Wait a second to let the server start up
setTimeout(function() {
var clientRequest = https.request(options, function(res) {
res.on('data', function (chunk) {
console.log('Called')
})
})
clientRequest.write('')
clientRequest.end()
}, 1000)
I get the error even with the server and client running on different node instances and have tested with port 8000, 3000, and 443 and with and without the SSL certificates. I do have libssl and libssl-dev on my Ubuntu machine.
Any ideas on what could be the cause?
In
https.createServer(function (req, res) {
you are missing options when you create the server, should be:
https.createServer(options, function (req, res) {
with your key and cert inside
I had a very similar problem where the response's end event never fired.
Adding this line fixed the problem:
// Hack to emit end on close because of a core bug that never fires end
response.on('close', function () {response.emit('end')});
I found an example of this in the request library mentioned in the previous answer.
Short answer: Use the the latest source code instead of the one you have. Store it where you will and then require it, you are good to go.
In the request 1.2.0 source code, main.js line 76, I see
http.createClient(options.uri.port, options.uri.hostname, options.uri.protocol === 'https:');
Looking at the http.js source code, I see
exports.createClient = function(port, host) {
var c = new Client();
c.port = port;
c.host = host;
return c;
};
It is requesting with 3 params but the actual function only has 2. The functionality is replaced with a separate module for https.
Looking at the latest main.js source code, I see dramatic changes. The most important is the addition of require('https').
It appears that request has been fixed but never re-released. Fortunately, the fix seems to work if you just copy manually from the raw view of the latest main.js source code and use it instead.
I had a similar problem and i think i got a fix. but then I have another socket problem.
See my solution here: http://groups.google.com/group/nodejs/browse_thread/thread/9189df2597aa199e/b83b16c08a051706?lnk=gst&q=hang+up#b83b16c08a051706
key point: use 0.4.8, http.request instead of http.createClient.
However, the new problem is, if I let the program running for long time, (I actually left the program running but no activity during weekend), then I will get socket hang up error when I send a request to http Server. (not even reach the http.request). I don't know if it is because of my code, or it is different problem with http Server