doude1917 2018-11-13 22:06
浏览 55

I / O超时连接到Firebase

Yesterday everything was worked as expected in my Go application. I didn't change anything related to firewalls/configurations. Today when I'm trying to send a request to "https://fcm.googleapis.com/fcm/send" I got the next errors:

Post https://fcm.googleapis.com/fcm/send: dial tcp: lookup fcm.googleapis.com on IP:53: read udp IP:37987->IP:53: i/o timeout

I don't know how this error happen. Firewall configuration still the same. The weird is that If I test locally then it works fine but when I upload to my server I got that error.

NGINX Configuration under Plesk:

server_name mydomain.com;

location /api/v1 {

    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    fastcgi_read_timeout 2500;
    proxy_connect_timeout      2500;
    proxy_send_timeout         2500;
    proxy_read_timeout         2500;
    send_timeout               2500;
    proxy_pass          http://localhost:8082/api/v1;
}

UPDATE Checking the logs I got this from NGINX

499 POST /api/v1/notifications HTTP/1.1

My domain doesnt have a SSL Certificate, can this be the cause of timeout?

UPDATE Code:

client, err := fcm.NewClient("KEY")
    if err != nil {
        fmt.Println(err)
    }

    handler.FirebaseClient = client
firebaseNotification := &fcm.Message{
        Notification: &fcm.Notification{
            Title: notificationData.Title,
            Body:  notificationData.Body,
        },
    }
firebaseNotification.RegistrationIDs = notificationData.Tokens

        fmt.Println(firebaseNotification)
        _, err := FirebaseClient.Send(firebaseNotification)
if err != nil {
            fmt.Println(err)
            return
        }

Send function from the library github.com/appleboy/go-fcm

func (c *Client) send(data []byte) (*Response, error) {
    // create request
    req, err := http.NewRequest("POST", c.endpoint, bytes.NewBuffer(data))
    if err != nil {
        return nil, err
    }

    // add headers
    req.Header.Add("Authorization", fmt.Sprintf("key=%s", c.apiKey))
    req.Header.Add("Content-Type", "application/json")

    // execute request
    resp, err := c.client.Do(req)
    if err != nil {
        return nil, connectionError(err.Error())
    }
    defer resp.Body.Close()

    // check response status
    if resp.StatusCode != http.StatusOK {
        if resp.StatusCode >= http.StatusInternalServerError {
            return nil, serverError(fmt.Sprintf("%d error: %s", resp.StatusCode, resp.Status))
        }
        return nil, fmt.Errorf("%d error: %s", resp.StatusCode, resp.Status)
    }

    // build return
    response := new(Response)
    if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
        return nil, err
    }

    return response, nil
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器