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

Improve APNs http2 connection health check #568

Merged
merged 2 commits into from
May 4, 2021

Conversation

yokotaso
Copy link
Contributor

@yokotaso yokotaso commented May 4, 2021

From Best Practices for Managing Connections,

You can check the health of your connection using an HTTP/2 PING frame.

And I happened when gorush try to send push to APNs, But cached http/2
connection is not available.Therefore I thik it is good that gorush
check APN/2 connection availability by HTTP/2 PING frame.

Here is a test code in local. With environment variable GODEBUG=http2debug=2, you can see a ping/2 log.

func TestHTTP2Ping(t *testing.T) {
	PushConf.Ios.Enabled = true
	PushConf.Ios.KeyPath = "../certificate/authkey-valid.p8"
	PushConf.Ios.TeamID = "example.team"
	PushConf.Ios.KeyID = "example.key"
	PushConf.Core.HTTPProxy = ""
	err := InitAPNSClient()
	assert.Nil(t, err)
	assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host)

	for i := 1; i <= 10; i++ {
		if resp, err := ApnsClient.HTTPClient.Head(apns2.HostDevelopment); err != nil {
			t.Fatal(err)
		} else {
			assert.Equal(t, 405, resp.StatusCode)
			time.Sleep(time.Second * 10)
		}
	}
}

Ping log looks like below:

2021/05/04 17:17:20 http2: Framer 0xc0015d49a0: wrote PING len=8 ping="F\x9a\x11\x9b\xb7\x17\v*"
2021/05/04 17:17:20 http2: Framer 0xc0015d49a0: read PING flags=ACK len=8 ping="F\x9a\x11\x9b\xb7\x17\v*"
2021/05/04 17:17:20 http2: Transport received PING flags=ACK len=8 ping="F\x9a\x11\x9b\xb7\x17\v*"
2021/05/04 17:17:21 http2: Framer 0xc0015d49a0: wrote PING len=8 ping="\x05\xf1\xb8PP\xcdp\x99"
2021/05/04 17:17:21 http2: Framer 0xc0015d49a0: read PING flags=ACK len=8 ping="\x05\xf1\xb8PP\xcdp\x99"
2021/05/04 17:17:21 http2: Transport received PING flags=ACK len=8 ping="\x05\xf1\xb8PP\xcdp\x99"

From [Best Practices for Managing Connections](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html),

> You can check the health of your connection using an HTTP/2 PING frame.

And I happened when gorush try to send push to APNs, But cached http/2
connection is not available.Therefore I thik it is good that gorush
check APN/2 connection availability by HTTP/2 PING frame.
@yokotaso yokotaso force-pushed the ping-connection branch from 7127b78 to 678e82d Compare May 4, 2021 08:11
@yokotaso yokotaso marked this pull request as ready for review May 4, 2021 08:16
@appleboy appleboy merged commit 01aba27 into appleboy:master May 4, 2021
@appleboy
Copy link
Owner

appleboy commented May 4, 2021

@yokotaso Thanks.

@yokotaso yokotaso deleted the ping-connection branch June 1, 2021 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants