enough_mail
enough_mail copied to clipboard
looks like "enough_mail" is keeping sockets open
looks like "enough_mail" is keeping sockets open I have seen a backlog of connections in state (CLOSE_WAIT)
Dart SDK version: 2.12.4 (stable) (Unknown timestamp) on "linux_x64"
...
TCP srv-jubarte.riodasostras.rj.gov.br:58904->zimbra.riodasostras.rj.gov.br:imaps (CLOSE_WAIT)
...
environment:
sdk: ">=2.10.0 <3.0.0"
dependencies:
enough_mail: ^1.3.6
import 'package:enough_mail/enough_mail.dart';
class ZimbraService {
ZimbraService();
Future<List<Map<String, dynamic>>> getLastInboxMessagesAsMap(
String username, String password) async {
var results = <Map<String, dynamic>>[];
ImapClient client;
try {
client = ImapClient(isLogEnabled: false);
final comInfo = await client.connectToServer(
'zimbra.riodasostras.rj.gov.br', 993,
isSecure: true);
final capabilities = await client.login(username, password);
await client.selectInbox();
var fetchResult = await client.fetchRecentMessages(
messageCount: 3, criteria: '(UID ENVELOPE)');
var messages = fetchResult.messages;
for (final message in messages) {
//print(message);
var timestamp = message.decodeDate();
var data = '${timestamp.day}/${timestamp.month}/${timestamp.year}';
var hora = '${timestamp.hour}:${timestamp.minute}:${timestamp.second}';
results.add({
'assunto': message.decodeSubject(),
'lido': message.isSeen,
'de': message.fromEmail,
'iniciais': message.fromEmail.substring(0, 2).toUpperCase(),
'timestamp': timestamp,
'data': data,
'hora': hora
});
}
results.sort((a, b) {
var adate = a['timestamp']; //before -> var adate = a.expiry;
var bdate = b['timestamp']; //var bdate = b.expiry;
return -adate.compareTo(bdate);
});
} catch (e) {
print('ZimbraService@getInboxAsMap error to get Mailbox $e');
} finally {
try {
await client.closeMailbox();
await client.logout();
await client.disconnect();
} catch (e) {
print('ZimbraService@getInboxAsMap error o close Mailbox $e');
}
}
return results;
}
}
Thanks for the report!
You seem to be using quite an old enough_mail version, please try updating to enough_mail: ^2.1.1
first.
When calling client.disconnect()
the following code is executed:
/// Disconnects from the service
Future<void> disconnect() async {
if (_isConnected) {
logApp('disconnecting');
isLoggedIn = false;
_isConnected = false;
isSocketClosingExpected = true;
try {
await _socketStreamSubscription.cancel();
} catch (e) {
print('unable to cancel subscription $e');
}
try {
await _socket.close();
} catch (e) {
print('unable to close socket $e');
}
}
}
Is there something additional that should be done to clean up sockets?