Skip to content

Conversation

@Alexander-Cairns
Copy link
Contributor

@Alexander-Cairns Alexander-Cairns commented Jul 9, 2025

Fixes an issue where the response was not being sent due to an issue with how
yaegi handles inline defers.

Fixes #8

@Alexander-Cairns Alexander-Cairns added the patch Backwards compatible bug fixes. label Jul 9, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 9, 2025

Walkthrough

The changes refactor a timing/logging function in botblocker.go by extracting an inline deferred function into a separate named function, getTimer. In docker-compose.yml, service dependencies, image versions, log levels, and curl command timeouts are updated for several services to improve startup order, logging verbosity, and request handling.

Changes

Files Change Summary
botblocker.go Refactored inline deferred timing/logging function into a named function getTimer.
docker-compose.yml Updated Traefik image version; added service dependencies; changed log level; set curl timeouts; added stop_grace_period.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Traefik
    participant BotBlocker
    participant Whoami

    Client->>Traefik: HTTP Request
    Traefik->>BotBlocker: Pass request to middleware
    BotBlocker->>BotBlocker: Start timer (getTimer)
    BotBlocker-->>BotBlocker: Check request (block/allow)
    BotBlocker-->>BotBlocker: Log elapsed time (deferred getTimer)
    alt Allowed
        BotBlocker->>Whoami: Forward request
        Whoami->>Traefik: Response
        Traefik->>Client: Response
    else Blocked
        BotBlocker->>Traefik: Block response
        Traefik->>Client: Blocked response
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Middleware should respond to client, not stall requests (#8)
Ensure logging/timing does not interfere with response flow (#8)
Service dependencies and startup order improved for plugin testing (#8)

Poem

In the meadow of code, a function took flight,
From inline to named, now tidy and right.
The services line up, no more delay,
With logs set to DEBUG, all clear as day.
🐇 Hopping forward, requests now flow—
The bot blocker’s fixed, let traffic go!

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 275008a and 8e2dcfe.

📒 Files selected for processing (2)
  • botblocker.go (2 hunks)
  • docker-compose.yml (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
botblocker.go (1)
utils/log.go (1)
  • Debugf (105-109)
🔇 Additional comments (7)
botblocker.go (2)

184-186: LGTM! Clean refactoring to resolve yaegi interpreter issue.

The extraction of the inline deferred function into a separate named function is a good solution to work around the yaegi interpreter's handling of inline defers. The logic and timing measurement remain unchanged, and the explicit comment documents the rationale for this change.


228-232: Well-implemented timer function.

The getTimer function correctly captures the start time and returns a closure that logs the elapsed time when called. This maintains the same functionality as the original inline defer while avoiding the yaegi interpreter issue.

docker-compose.yml (5)

18-19: Good dependency management.

Adding the lists service dependency ensures proper startup ordering, which is important since the botblocker plugin fetches blocklists from this service.


29-29: Log level change aligns with code improvements.

Changing the log level to DEBUG complements the timing logging improvements in botblocker.go, enabling more detailed runtime diagnostics during testing.


43-43: Excellent addition of curl timeouts.

Adding the -m 5s timeout to curl commands prevents hanging requests in the test environment, which is especially important for testing bot blocking functionality.

Also applies to: 62-62, 81-81, 100-100


49-52: Proper service orchestration for test services.

The addition of service dependencies and stop_grace_period: 0s for test services ensures proper startup ordering and quick shutdown during testing, which improves the overall test experience.

Also applies to: 68-71, 87-90, 106-109


4-4: Verify Traefik v3.4 Compatibility

The automated check against the GitHub API for tag v3.4 did not surface any “breaking” or “plugin” notes. Please manually review the official release notes (e.g. https://github.com/traefik/traefik/releases/tag/v3.4.0) to confirm:

  • No breaking changes impacting our existing plugin implementations
  • Configuration syntax and defaults remain compatible
  • Any adjustments needed for middleware, routing or CLI flags
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@lutaylor lutaylor left a comment

Choose a reason for hiding this comment

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

Approved assuming we are going to lower logging level

@Alexander-Cairns Alexander-Cairns merged commit da43f03 into main Jul 9, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Backwards compatible bug fixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Middleware never responds to client

3 participants