voodoodyne / subethasmtp

SubEtha SMTP is a Java library for receiving SMTP mail
Other
352 stars 139 forks source link

Memory leakage #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I process a lot of message and after a few hrs application crash with 
OutOfMemory exception in 3.1.4 (I've attached profiler screenshot):

MessageHandler class looks like this:
=
public class MyMessageHandler implements MessageHandlerFactory {

    public MessageHandler create(MessageContext ctx) {
        return new Handler(ctx);
    }

    class Handler implements MessageHandler {
        MessageContext ctx;

        public Handler(MessageContext ctx) {
            this.ctx = ctx;
        }

        public void from(String from) throws RejectException {
        }

        public void recipient(String recipient) throws RejectException {
        }

        public void data(InputStream data) throws IOException {
            Logger logger = LoggerFactory.getLogger(MyMessageHandler.class);
            final IndexImpl ii = new IndexImpl();

            // We cannot read InputStream twice, so convert to ByteArray
            byte[] dataArr = toByteArray(data);
            data.close();

// other code
            } catch (Exception e) {
                logger.error("Cannot save message", e);
                throw new RejectException(450, e.getMessage());
            }
        }

        public void done() {
        }
    }

    private static byte[] toByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        int size;
        byte[] cBuf = new byte[4096];
        while ((size = is.read(cBuf)) != -1) {
            bos.write(cBuf,0,size);
        }
        bos.close();
        return bos.toByteArray();
    }
}
===

Original issue reported on code.google.com by maxi...@gmail.com on 1 May 2011 at 8:53

Attachments:

GoogleCodeExporter commented 9 years ago
Isn't that screenshot showing that all the leaked objects are apache poi 
objects?  That wouldn't have anything to do with SubEtha SMTP.

Original comment by lhori...@gmail.com on 2 May 2011 at 10:55

GoogleCodeExporter commented 9 years ago
Moreover, what do you mean on "lot of message"? I used an older version with 
months of uptime with 50 000 mails daily, and the current trunk does not show 
any leakage either. At least according to the top command, following a 24 hours 
period. You may want to remove the mentioned "other code", to check if it can 
be reproduced without that.

Original comment by hontvari@flyordie.com on 3 May 2011 at 7:14

GoogleCodeExporter commented 9 years ago

Original comment by hontvari@flyordie.com on 3 May 2011 at 7:14

GoogleCodeExporter commented 9 years ago
ok, thanks. I am trying to process a few millions messages per day.

Original comment by maxi...@gmail.com on 3 May 2011 at 11:20

GoogleCodeExporter commented 9 years ago
doesn't seem valid. we can reopen if this is a real issue.

Original comment by latch...@gmail.com on 4 May 2011 at 9:07