Free Support Forum - aspose.com

Aspose.Email Issue "2 CR Found" and recommended approach

Hi,

I randomly get the issue “2 CR Found” but I am unable to find description anywhere what causes this exception.
Could you please share what are the possible reasons for this exception?

We are using the Aspose Email to read all emails, move that email in other folder.
Connectivity approach is using clientId, secret, tenant, mailboxID, password .
PostRequest simply invokes oauth2 for authentication

String url = "https://login.microsoftonline.com/"+ tenantId + "/oauth2/token";

        HttpClient httpclient = HttpClients.createDefault();
        HttpPost httppost = new HttpPost(url);

        // Request parameters and other properties.
        httppost.setEntity(requestData);

        //Execute and get the response.
        HttpResponse httpResponse = null;
            httpResponse = httpclient.execute(httppost);
            HttpEntity entity = httpResponse.getEntity();

            if (entity != null) {
                try (InputStream instream = entity.getContent()) {
                    response = IOUtils.toString(instream);
                }
            }

Then initialize EWSClient in following manner:-

    bearerToken = new Gson().fromJson(response, BearerToken.class);
           OAuthNetworkCredential oAuthCredential = new OAuthNetworkCredential(bearerToken.access_token);
           iewsClient = EWSClient.getEWSClient(mailboxuri, oAuthCredential);

For every operation (readMail , moveMail) , new ewsClient is instantiated and disposed by setting it to null.
It is being used by multiple applications.
Multiple applications are creating ewsClient, performing operation on mailbox and then disposing.

What’s the recommended approach to handle such scenario?
I found following article, after which I changed static singleton client which was being shared by all applications into current non-static architecture.

Thanks

@curiousreedhub

I suggest you to please try using latest version of Aspose.Email 20.9.1 on your end. In case there is still an issue then please provide a working sample project and test account credentials verifying the issue on your end so that we may try to reproduce the same on our end.

Hi. I am using the latest version. But this is an intermittent issue. The approach I have explained above is that the correct one or should I make client singleton?
Please look at the latter part of my question.

Thanks

@curiousreedhub

This is something concerning too as on your end too its intermittent. In order to investigate and resolve the issue we need a working sample project and environment details that we may test on our end to help you further.

Sure I am working on sharing that. Any inputs on recommended approach?

@curiousreedhub

As requested earlier, we will need some working sample project that is reproducing issue on your end and we will try to reproduce the same on our end based oon that.

asposedemo.zip (107.4 KB)

Please find attached sample app. In our project, multiple application are using aspose client . We have tried to recreate this scenario using Scheduler.
Please do note that this issue only comes once in weeks or so.
We are currently using “ModernAuthentication” and not basic authentication using IMAP.
Please test using ModernAuthentication only.

Project Information:

Sample project for reading the unread mail and move to destFolder.
In AsposeMailheper class change the mailId and Password.
In Scheduler class change the FromFolder and ToFolder.

We do have aspose.email 1 year support as well.

Exception stacktrace:

com.aspose.email.system.exceptions.WebException: 2 CR found
com.aspose.email.internal.o.ze.b(Unknown Source)
com.aspose.email.internal.o.ze.c(Unknown Source)
com.aspose.email.internal.o.ze.a(Unknown Source)
com.aspose.email.internal.o.ze.b(Unknown Source)
com.aspose.email.internal.o.zbh.a(Unknown Source)
com.aspose.email.internal.o.zbi.invoke(Unknown Source)
com.aspose.email.system.zd.a(Unknown Source)
com.aspose.email.internal.ex.zc.a(Unknown Source)
com.aspose.email.internal.ah.zg.run(SourceFile:66)
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:834)

 java.lang.RuntimeException: class com.aspose.email.system.exceptions.WebException: 2 CR found
com.aspose.email.internal.o.ze.b(Unknown Source)
com.aspose.email.internal.o.ze.c(Unknown Source)
com.aspose.email.internal.o.ze.a(Unknown Source)
com.aspose.email.internal.o.ze.b(Unknown Source)
com.aspose.email.internal.o.zbh.a(Unknown Source)
com.aspose.email.internal.o.zbi.invoke(Unknown Source)
com.aspose.email.system.zd.a(Unknown Source)
com.aspose.email.internal.ex.zc.a(Unknown Source)
com.aspose.email.internal.ah.zg.run(SourceFile:66)
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java.base/java.lang.Thread.run(Thread.java:834)

Kindly help in identifying and resolving the issue. It’s at very critical stage for us.

Thank you

@curiousreedhub

I have created an issue with ID EMAILJAVA-34759 in our issue tracking system to further investigate this intermittent issue. We will share the feedback with you as soon as the issue will be addressed.

Hi.

Thanks. Can you have please share any timeline/ETA on it?
Also, if you could suggest probable root causes for “2 CR Found” exception we could look at our end as well.

We have multiple clients connecting with mailbox in parallel.

Please provide your input.

Thanks

@curiousreedhub

We can use single EwsClient instance for one user credentials. We have tested scheduler with our test account.
We suggest you to enable new EwsClient core implementation using option:

EWSClient.useSAAJAPI(true);

Should we use single client instance for one user credential for IMAP as well as SMTP?
In that case can we make it static per credential as in our functionality multiple independent applications have to connect with the same email and do following operations:

  1. Read email folder and list emails
  2. Do processing and move email
  3. Send Email

Also, could you please elaborate on SAAJ? I could only find below brief in documentations:
Sets value indicating whether SAAJ is used.

Thanks for your support

@curiousreedhub

We will get back to you with feedback on this as soon as it will be shared.