Skip to content

FIX: Preventing segfault when Cloudflare API limit is reached#1530

Merged
tlimoncelli merged 2 commits intoStackExchange:masterfrom
jpbede:fix/cloudflare-segfault
Jun 9, 2022
Merged

FIX: Preventing segfault when Cloudflare API limit is reached#1530
tlimoncelli merged 2 commits intoStackExchange:masterfrom
jpbede:fix/cloudflare-segfault

Conversation

@jpbede
Copy link
Copy Markdown
Collaborator

@jpbede jpbede commented Jun 8, 2022

This PR prevents segfaults when the Cloudflare API limit (1.2k req per 5mins) is reached and should be handled correctly.

This PR partially fix #1440, DNSControl will no longer panic and provide a meaningful error message to the user.

@tlimoncelli
Copy link
Copy Markdown
Contributor

CC: @tresni

I cloned this to #1531 so that the tests would run (Github doesn't expose secrets to outside PR).

if resp, err := c.cfClient.CreateDNSRecord(context.Background(), domainID, cf); err != nil {
return err
} else {
id = resp.Result.ID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably missing something obvious but why set a variable just before a "return nil" statement? I suspect either the id = or return nil isn't needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i see, id = is required at L164 to enable the proxy mode. And return nil is required as the function for F requires a return type:

arr := []*models.Correction{{
	Msg: fmt.Sprintf("CREATE record: %s %s %d%s %s", rec.GetLabel(), rec.Type, rec.TTL, prio, content),
	F: func() error {}
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH! The "id" variable is stored outside of the function! I get it. It's being updated by side-effect.

Could you add a comment like, "Updating id (from the outer scope) by side-effect" for future me ("future me" has terrible memory).

Thanks!

Signed-off-by: Jan-Philipp Benecke <[email protected]>
@tlimoncelli tlimoncelli merged commit 60324bc into StackExchange:master Jun 9, 2022
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.

CLOUDFLAREAPI: DNSControl push panics when >1000 corrections

3 participants