Skip to content

Conversation

@ahmed3mar
Copy link
Contributor

📑 Description

  1. Get fresh installation of goravel
  2. Add fiber https://github.com/goravel/fiber
  3. add http context to Orm
func (r *UserController) Index(ctx http.Context) http.Response {
	var users []models.User
	facades.Orm().WithContext(
        	ctx, // <-- this
	).Query().Find(&users)
	return ctx.Response().Success().Json(http.Json{
		"users": users,
	})
}

run stress test like wrk wrk -t12 -c400 -d40s http://127.0.0.1:3000/users

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x248 pc=0x106311c10]

goroutine 824 [running]:
github.com/valyala/fasthttp.(*RequestCtx).UserValue(...)
	/go/pkg/mod/github.com/valyala/fasthttp@v1.58.0/server.go:709
github.com/gofiber/fiber/v2.(*Ctx).UserContext(0x14000b36008)
	/go/pkg/mod/github.com/gofiber/fiber/v2@v2.52.6/ctx.go:467 +0x20
github.com/goravel/fiber.(*Context).Done(0x0?)
	/go/pkg/mod/github.com/goravel/fiber@v1.3.2/context.go:111 +0x20
database/sql.(*Rows).awaitDone(0x1400157efa0, {0x14f4b8008, 0x14000b38180}, {0x0, 0x0}, {0x106d0f368, 0x14000dace10})
	/opt/homebrew/Cellar/go/1.23.6/libexec/src/database/sql/sql.go:3002 +0x6c
created by database/sql.(*Rows).initContextClose in goroutine 50
	/opt/homebrew/Cellar/go/1.23.6/libexec/src/database/sql/sql.go:2988 +0x144
Process Exit with Code: 2

@coderabbitai summary

✅ Checks

  • Added test cases for my code

@ahmed3mar ahmed3mar requested a review from a team as a code owner February 7, 2025 08:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • 🚀 Review Ready

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@ahmed3mar ahmed3mar changed the title fix: Fix throw error if Context is http Context fix: Throw error if Context is http Context Feb 7, 2025
@codecov
Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.54%. Comparing base (7dabf8f) to head (744bb8f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #856   +/-   ##
=======================================
  Coverage   67.54%   67.54%           
=======================================
  Files         151      151           
  Lines       10343    10343           
=======================================
  Hits         6986     6986           
  Misses       2990     2990           
  Partials      367      367           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

func (r *Orm) WithContext(ctx context.Context) contractsorm.Orm {
if http, ok := ctx.(httpcontract.Context); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

I reproduced it, do you know what the root reason is, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know exactly, but I think due to Race Condition in fiber ctx is Done and become nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After doing some debug the issue only occured with fiber not with gin also if we comment this return will work fine
https://github.com/goravel/fiber/blob/master/context.go#L111. @hwbrzzl

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Great catch

@hwbrzzl hwbrzzl merged commit 346ff0a into goravel:master Feb 8, 2025
14 checks passed
@ahmed3mar ahmed3mar deleted the patch-4 branch February 8, 2025 11:10
hwbrzzl added a commit that referenced this pull request Jan 10, 2026
* fix: [#856] Distinct will no effect when using with Count

* fix: [#856] Distinct will no effect when using with Count

* optimize

* optimize

* optimize

* optimize

* optimize

* optimize
@gemini-code-assist gemini-code-assist bot mentioned this pull request Jan 10, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants