Skip to content

Commit

Permalink
feat(portable): plugin error message for func (#3305)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <[email protected]>
  • Loading branch information
ngjaying authored Oct 21, 2024
1 parent e19c37a commit 90fc2d5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/plugin/portable/runtime/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (r *NanomsgReqRepChannel) Req(arg []byte) ([]byte, error) {
}
}
if err != nil {
return nil, fmt.Errorf("can't send message on function rep socket: %s", err.Error())
return nil, err
}
result, e := r.sock.Recv()
if e != nil {
Expand Down
21 changes: 19 additions & 2 deletions internal/plugin/portable/runtime/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package runtime

import (
"encoding/json"
"errors"
"fmt"

"github.com/lf-edge/ekuiper/contract/v2/api"
nerrors "go.nanomsg.org/mangos/v3/errors"

"github.com/lf-edge/ekuiper/v2/internal/conf"
kctx "github.com/lf-edge/ekuiper/v2/internal/topo/context"
Expand Down Expand Up @@ -86,7 +88,8 @@ func (f *PortableFunc) Validate(args []interface{}) error {
}
res, err := f.dataCh.Req(jsonArg)
if err != nil {
return err
e := handleTimeout(err, f.reg.Name)
return e
}
fr := &FuncReply{}
err = json.Unmarshal(res, fr)
Expand All @@ -112,7 +115,8 @@ func (f *PortableFunc) Exec(ctx api.FunctionContext, args []any) (interface{}, b
}
res, err := f.dataCh.Req(jsonArg)
if err != nil {
return err, false
e := handleTimeout(err, f.reg.Name)
return e, false
}
fr := &FuncReply{}
err = json.Unmarshal(res, fr)
Expand All @@ -129,6 +133,19 @@ func (f *PortableFunc) Exec(ctx api.FunctionContext, args []any) (interface{}, b
return fr.Result, fr.State
}

func handleTimeout(err error, pname string) error {
if errors.Is(err, nerrors.ErrRecvTimeout) {
pm := GetPluginInsManager()
status, ok := pm.GetPluginInsStatus(pname)
if !ok {
return fmt.Errorf("plugin %s was removed", pname)
} else {
return fmt.Errorf("time out, plugin %s status %s, message: %s", pname, status.Status, status.ErrMsg)
}
}
return err
}

func (f *PortableFunc) IsAggregate() bool {
if f.isAgg > 0 {
return f.isAgg > 1
Expand Down
1 change: 0 additions & 1 deletion internal/plugin/portable/runtime/plugin_ins_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func (p *pluginInsManager) GetOrStartProcess(pluginMeta *PluginMeta, pconf *Port
cmd.Stdout = conf.Log.Out
cmd.Stderr = conf.Log.Out
cmd.Dir = filepath.Dir(pluginMeta.Executable)

conf.Log.Println("plugin starting")
err = cmd.Start()
failpoint.Inject("cmdStartErr", func() {
Expand Down

0 comments on commit 90fc2d5

Please sign in to comment.