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

RuntimeContext is shared accross request by pointer , SetSyncRequest and GetSyncRequest is unpredictable ? #75

Closed
binnn6 opened this issue Nov 16, 2023 · 5 comments · Fixed by #77
Assignees

Comments

@binnn6
Copy link
Contributor

binnn6 commented Nov 16, 2023

func (r *Runtime) RegisterHTTPFunction(
	ctx ofctx.RuntimeContext,
	prePlugins []plugin.Plugin,
	postPlugins []plugin.Plugin,
	rf *functions.RegisteredFunction,
) error {
	route := r.handler.HandleFunc(rf.GetPath(), func(w http.ResponseWriter, r *http.Request) {
		rm := runtime.NewRuntimeManager(ctx, prePlugins, postPlugins)
		// save the Vars into the context
		_ctx := ofctx.CtxWithVars(r.Context(), ofctx.Vars(r))
		rm.FuncContext.SetNativeContext(_ctx)
		rm.FuncContext.SetSyncRequest(w, r.WithContext(_ctx))
		defer RecoverPanicHTTP(w, "Function panic")
		rm.FunctionRunWrapperWithHooks(rf.GetHTTPFunction())
	})

	// add methods matcher if any
	methods := rf.GetFunctionMethods()
	if len(methods) > 0 {
		route.Methods(methods...)
	}

	return nil
}

Since RuntimeContext is shared accross request by pointer , SetSyncRequest and GetSyncRequest is unpredictable ? or it should pass by value?

@binnn6
Copy link
Contributor Author

binnn6 commented Nov 16, 2023

pr here #77

@wanjunlei
Copy link
Member

Why SetSyncRequest and GetSyncRequest is unpredictable? Is there anyone who will change the RuntimeContext?

@binnn6
Copy link
Contributor Author

binnn6 commented Nov 17, 2023

Every request will call SetSyncRequest, so change RuntimeContext. So while just after request A call SetSyncRequest, request B call GetSyncRequest, request B will not be processed. since request B get request and response set by Request A.

@binnn6
Copy link
Contributor Author

binnn6 commented Nov 17, 2023

Reqeust A and Request B come in at the same time, Reqeust A may be exec 2 times, while Reqeust B 0 times. @wanjunlei

@wanjunlei
Copy link
Member

OK, I understand.

@benjaminhuo benjaminhuo linked a pull request Nov 22, 2023 that will close this issue
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 a pull request may close this issue.

4 participants