Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP connection not closed when undef'ing variable (Cyrus::IMAP::Admin) #9

Open
lakebranch opened this issue Jul 25, 2016 · 2 comments
Labels
2.4 affects 2.4

Comments

@lakebranch
Copy link

We recently moved from Cyrus 2.4.17 running on a FreeBSD system to Cyrus 2.4.18 on an Ubuntu 16.04 64bit system. We have a long running Perl script (basically a TCP server accepting administrative commands) that interfaces with Cyrus::IMAP::Admin. It does things similar to cyradm. When it wants to disconnect from the IMAP server, it undef's the variable holding the object reference - in the same way as cyradm. This works fine in the previous setup but on the new system the TCP connection doesn't close when the variable is undef'ed. Eventually, the connection moves from ESTABLISHED to CLOSE_WAIT (when the corresponding imapd process hangs up) but since the Cyrus::IMAP:Admin script never closes the connection, a lot of filehandles gets created over time. Eventually, all available FDs will be consumed and strange things will happen. The only solution is to restart the process.

I have verified (using sockstat on FreeBSD and lsof on Ubuntu) that the connection is closed when the variable is undef'ed on the FreeBSD system - but not on the Ubuntu system. I have also verified that cyradm exhibits the same behaviour on the Ubuntu system when issuing the disconnect command.

I've been pondering different reasons for this, including how garbage collection is done in Perl and so on, but I can't find a reason.

FreeBSD: This is perl 5, version 16, subversion 3 (v5.16.3) built for amd64-freebsd-thread-multi
Ubuntu: This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-linux-gnu-thread-multi

@elliefm
Copy link
Contributor

elliefm commented Jul 27, 2016

For what it's worth (maybe not much), perl/imap/IMAP/Admin.pm didn't change in the repository between 2.4.17 and 2.4.18. Did FreeBSD/Ubuntu apply any patches of their own?

I have also verified that cyradm exhibits the same behaviour on the Ubuntu system when issuing the disconnect command.

Could you clarify please: do you mean "cyradm on Ubuntu works the same as it did on FreeBSD", or do you mean "cyradm on Ubuntu breaks in the same way our script does on Ubuntu"?

@lakebranch
Copy link
Author

cyradm on our FreeBSD system drops the connection when I issue the disconnect command. In the source code, the scalar containing the object reference is set to undef.

cyradm on the Ubuntu system does the same thing in source code but the connection stays around until cyradm is terminated.

I guess it relies on garbage collection and/or some chain of destructors to break down everything. This seems to work on our FreeBSD system but not on our Ubuntu system.

I need a way to close the connection properly in a long running process - without resorting to terminating the whole process.

@elliefm elliefm added the 2.4 affects 2.4 label Aug 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.4 affects 2.4
Projects
None yet
Development

No branches or pull requests

2 participants