@@ -201,6 +201,45 @@ func TestHealthCheckInvalidMethod(t *testing.T) {
201201 r .Contains (string (content ), "this endpoint may only be called with either HEAD or GET method" )
202202}
203203
204+ func TestPanicRecovery (t * testing.T ) {
205+ r := require .New (t )
206+ location := "/tmp/test-plugin-panic-plugin.socket"
207+ output := bytes .NewBuffer (nil )
208+ ctx := context .Background ()
209+ p := NewPlugin (ctx , slog .Default (), types.Config {
210+ ID : "test-plugin-panic" ,
211+ Type : types .Socket ,
212+ PluginType : types .ComponentVersionRepositoryPluginType ,
213+ }, output )
214+
215+ t .Cleanup (func () {
216+ r .NoError (os .RemoveAll (location ))
217+ })
218+
219+ r .NoError (p .RegisterHandlers (endpoints.Handler {
220+ Handler : func (writer http.ResponseWriter , request * http.Request ) {
221+ panic ("test panic" )
222+ },
223+ Location : "/panic-endpoint" ,
224+ }))
225+
226+ go func () {
227+ _ = p .Start (ctx )
228+ }()
229+
230+ httpClient := createHttpClient (location )
231+ waitForPlugin (r , httpClient )
232+
233+ resp , err := httpClient .Get ("http://unix/panic-endpoint" )
234+ r .NoError (err )
235+ r .Equal (http .StatusInternalServerError , resp .StatusCode )
236+ content , err := io .ReadAll (resp .Body )
237+ r .NoError (err )
238+ r .Contains (string (content ), "panic recovered" )
239+
240+ r .NoError (p .GracefulShutdown (ctx ))
241+ }
242+
204243func waitForPlugin (r * require.Assertions , httpClient * http.Client ) {
205244 r .Eventually (func () bool {
206245 resp , err := httpClient .Get ("http://unix/healthz" )
0 commit comments