Skip to content

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

Closed

Description

@sureshthirumurugan

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

Activity

  1. thinkingserious commented on Jan 26, 2017

    @thinkingserious
    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!

  2. added
    type: question
    on Jan 26, 2017
  3. gabber12 commented on Nov 11, 2017

    @gabber12

    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

  4. gabber12 commented on Nov 13, 2017

    @gabber12

    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.

  5. mbernier commented on Nov 13, 2017

    @mbernier
    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!!

  6. added
    type: community enhancement
    status: help wanted
    difficulty: medium
    and removed
    type: question
    on Feb 28, 2018
  7. MatteoGioioso commented on May 6, 2019

    @MatteoGioioso

    same issue

  8. thinkingserious commented on Mar 11, 2021

    @thinkingserious
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: mediumstatus: help wantedtype: community enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions