Skip to content

Http concurrency limiter - #35820

Closed
Clamenda wants to merge 3 commits into
evcc-io:masterfrom
Clamenda:http-concurrency-limiter
Closed

Clamenda wants to merge 3 commits into
evcc-io:masterfrom
Clamenda:http-concurrency-limiter

Conversation

@Clamenda

@Clamenda Clamenda commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fix #35752

As stated in issue #35752, this solves the problem when a HTTP server allows only a certain number of concurrent requests. In the case of Open-Meteo, only 5 concurrent requests are allowed.

It adds an optional, generic concurrency configuration to the HTTP plugin containing a group and a limit. All HTTP plugin instances with the same group share the same semaphore with the configured limit over which the concurrency-limitation is handled. If no concurrency configuration is specified, the behavior is unchanged.

At the moment this concurrency limiter is only applied to the two Open-Meteo tariff templates.

@github-actions github-actions Bot added enhancement New feature or request infrastructure Basic functionality tariffs Specific tariff support labels Nov 5, 2026
@Clamenda
Clamenda marked this pull request as ready for review November 5, 2026 10:31

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="plugin/http.go" line_range="97" />
<code_context>
 		return nil, err
 	}
 	p.pipeline = pipe
+	p.ctx = ctx
+
+	limiter, err := cc.Concurrency.limiter()
</code_context>
<issue_to_address>
**Configured requests stop after setup**

When an HTTP plugin with concurrency enabled is created using a context that is canceled when its configuration request completes, `NewHTTPPluginFromConfig` retains the factory context in `p.ctx`, and `request` uses it for every limiter acquisition. Plugins created from the configuration API’s request context therefore fail with cancellation after the setup request ends, so their subsequent HTTP requests never reach the server.

Use a plugin-lifetime context for limiter waits, or pass a per-request context that remains valid for the plugin’s requests.
</issue_to_address>

### Comment 2
<location path="plugin/http_limit.go" line_range="60" />
<code_context>
+		group:    group,
+		limit:    limit,
+	}
+	httpConcurrencyGroups[group] = limiter
+	return limiter, nil
+}
</code_context>
<issue_to_address>
**Changed limits require restart**

When a plugin is reconfigured or removed and a later configuration reuses its group with a different limit, `httpConcurrencyGroups` retains the limiter after its plugin instances are removed, so constructing a replacement with the same group and a new limit returns a conflict and the reconfiguration fails.

Manage group registrations across reconfiguration, or provide a supported way to change a group's limit without restarting the process.
</issue_to_address>

### Comment 3
<location path="templates/definition/tariff/open-meteo-temperature.yaml" line_range="53-55" />
<code_context>
+```yaml
+source: http
+uri: https://example.org/forecast
+concurrency:
+  group: weather-provider
+  limit: 3
</code_context>
<issue_to_address>
**Open-Meteo docs omit concurrency configuration**

When either Open-Meteo tariff template gains the concurrency block, the generated template documentation stays out of sync with these tariff templates, so users consulting it do not see the new concurrency settings.

Run `make docs` and include the generated template documentation changes.

Also at `templates/definition/tariff/open-meteo.yaml:95-97`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread plugin/http.go Resolved
Comment thread plugin/http_limit.go Resolved
@andig

andig commented Nov 5, 2026

Copy link
Copy Markdown
Member

HTTP 429 is not related to concurrency.

@andig
andig marked this pull request as draft November 5, 2026 14:05
@Clamenda

Clamenda commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

That's what I also thought first, until I saw the response: reason:"Too many concurrent requests"

@andig

andig commented Nov 6, 2026

Copy link
Copy Markdown
Member

@Clamenda pls always mention the issue your PR fixes

@andig

andig commented Nov 6, 2026

Copy link
Copy Markdown
Member

Thanks for the PR and the trace log. The trace shows Open-Meteo answers 429 Too Many Requests without a Retry-After header, and evcc treated every 4xx as permanent so the request was never retried. #35898 retries 429 with the existing randomized backoff instead, which avoids a separate concurrency setting.

@Clamenda could you test #35898 with your seven Open-Meteo forecasts? A test build will be attached to that PR shortly. Please report whether all tariffs start without the 429 error.

🤖 Generated with Claude Code

@andig andig closed this Nov 6, 2026
@Clamenda

Clamenda commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Yes @andig, with #35898 I don't see any 429 errors in the log. Thanks.

@Clamenda
Clamenda deleted the http-concurrency-limiter branch November 7, 2026 09:34
@andig

andig commented Nov 7, 2026

Copy link
Copy Markdown
Member

And much simpler, no config required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request infrastructure Basic functionality tariffs Specific tariff support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optionally limit concurrent HTTP requests by context-group

2 participants