apns2 icon indicating copy to clipboard operation
apns2 copied to clipboard

dial tcp: xxxxxx read udp xxxxxx:38055->xxxxxx:53: i/o timeout

Open sshallow opened this issue 5 years ago • 1 comments

When I call apns2, it sometimes returns a timeout and the process will shut down. I am using go version go1.12.5 darwin/amd64 I have seen #24 and #21, I understand that they have solved it,but there will still be problems. My code

func ApplePushNotificationService(deviceToken string, parameters string) {
	fmt.Println("开始推送", deviceToken, parameters)
	cert, err := certificate.FromP12File("./hookupAPNS.p12", "******") //filename 为服务器上的p12文件地址
	if err != nil {
		log.Fatal("Cert Error:", err)
	}
	notification := &apns2.Notification{}
	notification.DeviceToken = deviceToken
	notification.Topic = "com.preferme.hookup"
	payload := payload.NewPayload().Alert(parameters).AlertBody(parameters).Badge(1).Sound("sound.wav").Custom("key", "val")
	notification.Payload = payload
	client := apns2.NewClient(cert).Production()
	res, err := client.Push(notification)
	if err != nil {
		log.Fatal("push Error:", err)
	}
	fmt.Printf("%v %v %v\n", res.StatusCode, res.ApnsID, res.Reason)
}

error log

push Error:Post https://api.development.push.apple.com/3/device/4dc8efa9c46b0206c2e6e0dda6a1314c457704f897747ae1f7dffe4ef31a443b: dial tcp: lookup api.development.push.apple.com on 10.143.22.116:53: read udp 10.116.213.185:38055->10.143.22.116:53: i/o timeout

sshallow avatar Jul 08 '19 03:07 sshallow

Hi @sshallow This looks like you could be using a proxy server and the problem is related to either that or a flakey internet connection rather than apns2. By default apns2.HTTPClientTimeout is set to 60 seconds. You could either try making that value larger (to reduce the timeout errors), or using a server with a better connection in the US. thanks

sideshow avatar Nov 30 '19 08:11 sideshow