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

Getting " api.sendgrid.com:443 failed to respond' when send mails through api calls #176

Closed
sureshthirumurugan opened this issue Dec 21, 2016 · 6 comments
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@sureshthirumurugan
Copy link

Issue Summary

Use SendGrid api call and send the mail to api.sendgrid.com (port 443) . Some mails are failing and getting the following errors.

2016-12-21 00:08:02.250 [ERROR] [pool-3-thread-17] MailUtil - Email not sent
org.apache.http.NoHttpResponseException: api.sendgrid.com:443 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143) ~[httpclient-4.4.jar:4.4]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) ~[httpclient-4.4.jar:4.4]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261) ~[httpcore-4.4.jar:4.4]
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165) ~[httpcore-4.4.jar:4.4]
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167) ~[httpclient-4.4.jar:4.4]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272) ~[httpcore-4.4.jar:4.4]
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124) ~[httpcore-4.4.jar:4.4]

Steps to Reproduce

Email from = new Email (fromEmail, fromUserName);
Content content = new Content ("text/html", " "); //else it willthrough excepton that body shouldn't be empty
Mail email = new Mail ();
email.setFrom (from);
email.addContent (content);
Personalization personalization = new Personalization ();
email.addPersonalization (personalization);
email.setTemplateId(sendGridWelcomeTemplateId);
personalization.addSubstitution("-firstName-", fname );
personalization.addSubstitution("-lastName-", lname);
personalization.addTo( new Email ( email ));
Request request = new Request ();
request.method = Method.POST;
request.endpoint = "mail/send";
request.body = email.build ();
Response response = sendGrid.api (request);
log.info ("Got status code " + response.statusCode);
  1. Create the template in sendgrid
  2. Use the above code snippet and try to send mails with random intervals.
  3. After some time sending mail will get the above exception. But same mail will get dispatched if you reattempt to send mails .

Failed mails will get delivered after 2 or 3 attempts. It seems due to some reason the api server of sendgrid is getting the request and failed to respond back . once timeout happens the above exception thrown. I attached the mtr log for send grid.
sendgrid_mtr.txt

Technical details:

  • Operating system: CentOS Linux 7 (3.10.0-229.14.1.el7.x86_64)
  • sendgrid-java 3.1.0
  • Java Version: 1.8
@thinkingserious
Copy link
Contributor

Hello @sureshthirumurugan,

It seems you might be running into a rate limiting problem. Check out this thread: sendgrid/sendgrid-php#173 (comment)

Please let me know what you find. Thanks!

@thinkingserious thinkingserious added the type: question question directed at the library label Jan 26, 2017
@gabber12
Copy link

gabber12 commented Nov 11, 2017

Facing a similar issue
This happens when resuing the same SendGrid.class instance for long.
My guess is the HttpClient connection is going stale and not handled properly.

! org.apache.http.NoHttpResponseException: api.sendgrid.com:443 failed to respond
! at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
! at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
! at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
! at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
! at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
! at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
! at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
! at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
! at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
! at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
! at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
! at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
! at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
! at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
! at com.sendgrid.Client.executeApiCall(Client.java:282)
! at com.sendgrid.Client.post(Client.java:192)
! at com.sendgrid.Client.api(Client.java:310)
! at com.sendgrid.SendGrid.makeCall(SendGrid.java:94)
! at com.sendgrid.SendGrid.api(SendGrid.java:113)

Java 1.8
sendgrid-java 4.1

@gabber12
Copy link

This happens if the sendgrid client is reused for multiple api calls for a long time.
Fixed it by using a ClientPool with a small expiry.

@mbernier
Copy link
Contributor

@gabber12 Would you be interested in creating a PR against this repo with this change? I think this could be very helpful for other users of the library!!

@mbernier mbernier reopened this Nov 13, 2017
@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap status: help wanted requesting help from the community difficulty: medium fix is medium in difficulty up-for-grabs and removed type: question question directed at the library labels Feb 28, 2018
@MatteoGioioso
Copy link

same issue

@thinkingserious
Copy link
Contributor

Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

6 participants