feat: 保留键解析fail-closed,启动期schema精度校验,部署期直派审批人校验

This commit is contained in:
rulego-team committed 2026-09-28 09:27:46 +08:00
1 parent 4caeb2e8b2
commit 314b7bbdd5
10 files changed
+454 -10

No files matched your search

+2 -2
View File
@@ -33,8 +33,8 @@ type Config struct {
Logging *LoggingConfig `json:"logging" yaml:"logging"`
// StrictTenantMembershipCheck 严格模式:宿主注入的 IdentityService 未实现
// TenantMembershipChecker 可选接口时,转派目标/startProcess 发起人/ccTask 抄送人的
// 跨租户归属校验整体跳过。默认 false 仅记启动告警;置 true 则引擎启动即失败
// (fail-fast)。多租户部署建议开启;单租户部署保持默认。
// 跨租户归属校验整体跳过。默认 false 仅记启动告警;置 true 则引擎启动即失败。
// 多租户部署建议开启;单租户部署保持默认。
StrictTenantMembershipCheck bool `json:"strict_tenant_membership_check" yaml:"strict_tenant_membership_check"`
}
+102
View File
@@ -0,0 +1,102 @@
// 部署期校验直派审批人(approver.type=user 的 userIds)存在且启用。
// 直派不经候选池展开,也不命中停用兜底链——落在已删除用户名下的任务
// 无人可办,实例就此卡死。宿主未实现 ActiveUserChecker 时整体跳过。
package service
import (
"context"
"fmt"
"sort"
"strings"
"github.com/rulego/gflow-engine/types/constants"
"github.com/rulego/rulego/api/types"
"github.com/sirupsen/logrus"
)
// deployDirectAssignees 汇集链内全部直派审批人(userTask 节点 approver.type=user
// 且 userIds 非空),返回 节点ID → userIds。节点配置是弱类型 map:与运行期
// 解析(components 的 ApproverConfig)同键,这里只读不依赖组件结构体。
func deployDirectAssignees(chain *types.RuleChain) map[string][]string {
out := map[string][]string{}
if chain == nil {
return out
}
for _, node := range chain.Metadata.Nodes {
if node.Type != constants.NodeTypeUserTask {
continue
}
cfg, ok := map[string]interface{}(node.Configuration)["approver"].(map[string]interface{})
if !ok {
continue
}
if t, _ := cfg["type"].(string); t != "user" {
continue
}
rawIDs, _ := cfg["userIds"].([]interface{})
var ids []string
for _, v := range rawIDs {
if s, ok := v.(string); ok && s != "" {
ids = append(ids, s)
}
}
if len(ids) > 0 {
out[node.Id] = ids
}
}
return out
}
// ValidateDirectAssignees 部署期直派审批人存在/启用校验。identity 未实现
// ActiveUserChecker 时跳过;身份服务查询失败时降级放行并告警——部署不被身份
// 服务抖动卡死,运行期还有停用兜底链与空审批人兜底两道网;存在幽灵/停用
// 直派时返回 ErrValidation,错误信息定位节点与具体 userId。
func ValidateDirectAssignees(ctx context.Context, identity IdentityService, tenantID string, chain *types.RuleChain) error {
if identity == nil || tenantID == "" {
return nil
}
checker, ok := identity.(ActiveUserChecker)
if !ok {
return nil
}
direct := deployDirectAssignees(chain)
if len(direct) == 0 {
return nil
}
uniqSet := make(map[string]bool)
for _, ids := range direct {
for _, id := range ids {
uniqSet[id] = true
}
}
uniq := make([]string, 0, len(uniqSet))
for id := range uniqSet {
uniq = append(uniq, id)
}
sort.Strings(uniq)
active, err := checker.AreActiveUsers(ctx, tenantID, uniq)
if err != nil {
logrus.WithError(err).WithField("tenantID", tenantID).
Warn("direct assignee check skipped: identity service query failed")
return nil
}
var issues []string
nodeIDs := make([]string, 0, len(direct))
for nodeID := range direct {
nodeIDs = append(nodeIDs, nodeID)
}
sort.Strings(nodeIDs)
for _, nodeID := range nodeIDs {
for _, id := range direct[nodeID] {
if !active[id] {
issues = append(issues, fmt.Sprintf("node %s 直派审批人 %q 不存在或已停用", nodeID, id))
}
}
}
if len(issues) > 0 {
return fmt.Errorf("invalid direct assignees: %w: %s", ErrValidation, strings.Join(issues, "; "))
}
return nil
}
+110
View File
@@ -0,0 +1,110 @@
// 部署期直派审批人校验测试:DSL 形状抽取、能力探测跳过、幽灵/停用拦截、
// create() 部署入口的拦截与放行(nil DAO panic = 守卫放行后走到 DAO)。
package service
import (
"context"
"strings"
"testing"
"github.com/rulego/gflow-engine/model"
"github.com/rulego/gflow-engine/types/enums"
"github.com/rulego/rulego/api/types"
"github.com/stretchr/testify/require"
)
// fakeActiveChecker 只实现 ActiveUserChecker 的身份服务桩。
type fakeActiveChecker struct {
IdentityService
active map[string]bool
err error
}
func (f *fakeActiveChecker) AreActiveUsers(_ context.Context, _ string, userIDs []string) (map[string]bool, error) {
if f.err != nil {
return nil, f.err
}
out := make(map[string]bool, len(userIDs))
for _, id := range userIDs {
out[id] = f.active[id]
}
return out, nil
}
// fakeEngineIdentity 只暴露 GetIdentityService 的引擎桩。
type fakeEngineIdentity struct {
WorkflowEngine
identity IdentityService
}
func (f *fakeEngineIdentity) GetIdentityService() IdentityService { return f.identity }
func directAssigneeDefinition(userIDs ...string) string {
quoted := make([]string, len(userIDs))
for i, u := range userIDs {
quoted[i] = `"` + u + `"`
}
return `{"ruleChain":{"additionalInfo":{}},` +
`"metadata":{"nodes":[{"id":"a","type":"userTask","configuration":{"approver":{"type":"user","userIds":[` +
strings.Join(quoted, ",") + `]}}}],"connections":[]}}`
}
func TestDeployDirectAssignees_Extraction(t *testing.T) {
chain := &types.RuleChain{Metadata: types.RuleMetadata{Nodes: []*types.RuleNode{
{Id: "direct", Type: "userTask", Configuration: types.Configuration{
"approver": map[string]interface{}{"type": "user", "userIds": []interface{}{"u1", "u2"}},
}},
// role 直派不校验(候选池运行期展开,有停用过滤)
{Id: "role", Type: "userTask", Configuration: types.Configuration{
"approver": map[string]interface{}{"type": "role", "userIds": []interface{}{"r1"}},
}},
// 非 userTask 节点忽略
{Id: "sw", Type: "switch"},
}}}
got := deployDirectAssignees(chain)
require.Equal(t, map[string][]string{"direct": {"u1", "u2"}}, got)
}
func TestValidateDirectAssignees(t *testing.T) {
ctx := context.Background()
chain := &types.RuleChain{Metadata: types.RuleMetadata{Nodes: []*types.RuleNode{
{Id: "a", Type: "userTask", Configuration: types.Configuration{
"approver": map[string]interface{}{"type": "user", "userIds": []interface{}{"u1", "ghost"}},
}},
}}}
// 幽灵/停用直派拒绝,错误定位节点与 userId
err := ValidateDirectAssignees(ctx, &fakeActiveChecker{active: map[string]bool{"u1": true}}, "t1", chain)
require.ErrorIs(t, err, ErrValidation)
require.Contains(t, err.Error(), "ghost")
require.Contains(t, err.Error(), "node a")
// 全部存在且启用:放行
require.NoError(t, ValidateDirectAssignees(ctx, &fakeActiveChecker{active: map[string]bool{"u1": true, "ghost": true}}, "t1", chain))
// 身份服务查询失败:降级放行(部署不被身份服务抖动卡死)
require.NoError(t, ValidateDirectAssignees(ctx, &fakeActiveChecker{err: context.DeadlineExceeded}, "t1", chain))
// 未实现 ActiveUserChecker:跳过
require.NoError(t, ValidateDirectAssignees(ctx, nil, "t1", chain))
// 租户为空:跳过
require.NoError(t, ValidateDirectAssignees(ctx, &fakeActiveChecker{}, "", chain))
}
// create() 部署入口:幽灵直派在校验块被拦(ErrValidation);直派全部有效则
// 守卫放行,流程继续走到 DAO(nil DAO panic 证明守卫未误拦)。
func TestCreate_DirectAssigneeGateAtDeploy(t *testing.T) {
newProc := func(def string) *model.WfProcess {
return &model.WfProcess{Name: "直派校验", ProcessKey: "dag-1", TenantID: "t1", DefinitionJSON: def}
}
ghost := &ProcessServiceImpl{engine: &fakeEngineIdentity{identity: &fakeActiveChecker{active: map[string]bool{"u1": true}}}}
_, err := ghost.create(context.Background(), newProc(directAssigneeDefinition("u1", "ghost")), false, string(enums.ProcessStatusActive))
require.ErrorIs(t, err, ErrValidation)
require.Contains(t, err.Error(), "ghost")
onlyActive := &ProcessServiceImpl{engine: &fakeEngineIdentity{identity: &fakeActiveChecker{active: map[string]bool{"u1": true}}}}
require.Panics(t, func() {
_, _ = onlyActive.create(context.Background(), newProc(directAssigneeDefinition("u1")), false, string(enums.ProcessStatusActive))
}, "直派全部有效应通过守卫(panic=nil DAO 到达)")
}
+9
View File
@@ -160,6 +160,15 @@ type TenantAdminResolver interface {
GetTenantAdminUserIDs(ctx context.Context, tenantID string) ([]string, error)
}
// ActiveUserChecker IdentityService 的可选扩展接口:宿主实现后,部署期校验
// 直派审批人(approver.type=user 的 userIds)存在且启用。未实现时跳过校验
// (引擎不含用户目录)。
type ActiveUserChecker interface {
// AreActiveUsers 批量判定用户存在且启用。返回 map 覆盖入参全部 userID,
// 不存在或已停用的值为 false。
AreActiveUsers(ctx context.Context, tenantID string, userIDs []string) (map[string]bool, error)
}
// GetUserFromCtx 从 ctx 取出 bindActor 绑定的操作人(*Actor);未绑定返回 nil。
func GetUserFromCtx(ctx context.Context) *Actor {
userV := ctx.Value(constants.KeyCurrentUser)
+13
View File
@@ -95,6 +95,12 @@ func (s *ProcessServiceImpl) Update(ctx context.Context, actor Actor, process *m
if issues := ValidateChainConfigurations(chain); len(issues) > 0 {
return fmt.Errorf("invalid node configuration: %w: %s", ErrValidation, FormatConfigIssues(issues))
}
// 直派审批人存在/启用校验:与 create 同口径(租户以存量定义为准)
if s.engine != nil {
if err := ValidateDirectAssignees(ctx, s.engine.GetIdentityService(), existingProcess.TenantID, chain); err != nil {
return err
}
}
}
// 保持原 processKey(忽略传入值,防破坏版本族)
process.ProcessKey = existingProcess.ProcessKey
@@ -206,6 +212,13 @@ func (s *ProcessServiceImpl) create(ctx context.Context, process *model.WfProces
if issues := ValidateChainConfigurations(chain); len(issues) > 0 {
return nil, fmt.Errorf("invalid node configuration: %w: %s", ErrValidation, FormatConfigIssues(issues))
}
// 直派审批人存在/启用校验(宿主实现 ActiveUserChecker 时生效):幽灵/停用
// 直派不经候选池展开也不命中停用兜底链,落库即成死任务,部署期拦下。
if s.engine != nil {
if err := ValidateDirectAssignees(ctx, s.engine.GetIdentityService(), process.TenantID, chain); err != nil {
return nil, err
}
}
// 兜底归一化(一次性,部署/创建时):
// 0. MigrateRouteGateway:遗留 routeGateway(引擎未注册,装载必失败)转 switch,
+120
View File
@@ -0,0 +1,120 @@
// 启动期校验引擎按毫秒比较的时间列精度。收回守卫按 ended_at 分序、按
// created_at>=ended_at 圈前沿终止集,列精度低于毫秒时同秒两票无法分序——
// 秒级列是早期 DDL 快照的中间态,规范 DDL 为 DATETIME(3),探到即拒绝启动。
package service
import (
"fmt"
"sort"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
// schemaTimePrecisionTargets 引擎按毫秒比较的列全集(表 → 时间列)。
// 与引擎建表脚本的 DATETIME(3) 基准对应;新增毫秒时序依赖时同步补这里。
var schemaTimePrecisionTargets = map[string][]string{
"wf_task": {"created_at", "ended_at", "updated_at"},
"wf_hi_task": {"created_at", "ended_at", "updated_at"},
}
// schemaPrecisionProbe information_schema 单列探测结果。Precision 用指针:
// 国产兼容实现对 DATETIME_PRECISION 可能返回 NULL,扫成 int 会变 0 被误判
// 成秒级,读不到精度按缺失(告警)处理而非拦截。
type schemaPrecisionProbe struct {
Table string `gorm:"column:table_name"`
Column string `gorm:"column:column_name"`
Precision *int `gorm:"column:datetime_precision"`
}
// SchemaPrecisionGuard 启动期列精度探测守卫。
type SchemaPrecisionGuard struct {
db *gorm.DB
}
// NewSchemaPrecisionGuard 创建守卫;db 为空(如单测装配无库引擎)时探测跳过。
func NewSchemaPrecisionGuard(db *gorm.DB) *SchemaPrecisionGuard {
return &SchemaPrecisionGuard{db: db}
}
// Validate 执行探测。低精度列返回错误拒绝启动(存量库先跑毫秒精度补丁再发版);
// 列缺失只告警,存在性由启动后首个查询自然暴露,本守卫只盯精度漂移;探测失败
// (方言/权限差异)也只告警,不因无法取证阻断启动。
func (g *SchemaPrecisionGuard) Validate() error {
if g == nil || g.db == nil {
return nil
}
var (
probes []schemaPrecisionProbe
err error
)
switch g.db.Dialector.Name() {
case "mysql":
probes, err = probeTimePrecision(g.db, `
SELECT TABLE_NAME AS table_name, COLUMN_NAME AS column_name, DATETIME_PRECISION AS datetime_precision
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME IN ('wf_task','wf_hi_task')
AND COLUMN_NAME IN ('created_at','ended_at','updated_at')`)
case "postgres":
probes, err = probeTimePrecision(g.db, `
SELECT table_name, column_name, datetime_precision
FROM information_schema.columns
WHERE table_name IN ('wf_task','wf_hi_task')
AND column_name IN ('created_at','ended_at','updated_at')`)
default:
// sqlite 及国产库专有方言(达梦等):无对应 information_schema 精度语义
// 或不经此守卫,跳过;MySQL/PG 协议兼容库走上方分支,探测失败只告警
return nil
}
if err != nil {
logrus.WithError(err).Warn("schema precision probe failed, skipping (advisory check)")
return nil
}
low, missing := evaluateSchemaPrecision(schemaTimePrecisionTargets, probes)
for _, m := range missing {
logrus.WithField("column", m).Warn("SCHEMA_TIME_COLUMN_MISSING: 引擎时序守卫依赖的列不存在(全新库未 init 或表名漂移),精度探测跳过该列")
}
if len(low) == 0 {
return nil
}
return fmt.Errorf("引擎时序依赖的时间列精度低于毫秒(收回守卫按 ended_at 毫秒分序,秒级列上同秒两票无法分序): %v;存量库请先执行毫秒精度补丁(对齐引擎 scripts 建表脚本的 DATETIME(3) 基准)再启动", low)
}
func probeTimePrecision(db *gorm.DB, query string) ([]schemaPrecisionProbe, error) {
var probes []schemaPrecisionProbe
if err := db.Raw(query).Scan(&probes).Error; err != nil {
return nil, fmt.Errorf("query information_schema: %w", err)
}
return probes, nil
}
// evaluateSchemaPrecision 归类探测结果(纯逻辑可单测):low=精度不足
// (毫秒时序依赖被打破),missing=列未建或精度读不到(NULL 视同缺失)。
// 遍历入参 map 顺序不定,返回前按表.列排序,保证报错与告警文本确定。
func evaluateSchemaPrecision(expected map[string][]string, probes []schemaPrecisionProbe) (low, missing []string) {
seen := make(map[string]int, len(probes))
for _, p := range probes {
if p.Precision == nil {
continue
}
seen[p.Table+"."+p.Column] = *p.Precision
}
for table, cols := range expected {
for _, col := range cols {
key := table + "." + col
precision, ok := seen[key]
if !ok {
missing = append(missing, key)
continue
}
if precision < 3 {
low = append(low, fmt.Sprintf("%s(%d)", key, precision))
}
}
}
sort.Strings(low)
sort.Strings(missing)
return low, missing
}
+61
View File
@@ -0,0 +1,61 @@
// 启动期 schema 精度校验测试:判定逻辑(纯函数)+ 跳过路径(sqlite/nil db)。
package service
import (
"testing"
"github.com/glebarez/sqlite"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
)
func intPtr(i int) *int { return &i }
func TestEvaluateSchemaPrecision(t *testing.T) {
expected := map[string][]string{
"wf_task": {"created_at", "ended_at"},
"wf_hi_task": {"ended_at"},
}
allMs := []schemaPrecisionProbe{
{Table: "wf_task", Column: "created_at", Precision: intPtr(3)},
{Table: "wf_task", Column: "ended_at", Precision: intPtr(3)},
{Table: "wf_hi_task", Column: "ended_at", Precision: intPtr(3)},
}
low, missing := evaluateSchemaPrecision(expected, allMs)
require.Empty(t, low)
require.Empty(t, missing)
// 秒级漂移(DATETIME 无精度):precision=0
second := append([]schemaPrecisionProbe{}, allMs...)
second[1].Precision = intPtr(0)
low, missing = evaluateSchemaPrecision(expected, second)
require.Equal(t, []string{"wf_task.ended_at(0)"}, low)
require.Empty(t, missing)
// 列缺失(全新库未 init / 表名漂移):只进 missing,不误报低精度
low, missing = evaluateSchemaPrecision(expected, allMs[:1])
require.Empty(t, low)
require.Equal(t, []string{"wf_hi_task.ended_at", "wf_task.ended_at"}, missing)
// 精度读不到(国产兼容实现返回 NULL):按缺失告警,不误判秒级
nullPrecision := []schemaPrecisionProbe{
{Table: "wf_task", Column: "created_at", Precision: intPtr(3)},
{Table: "wf_task", Column: "ended_at"},
{Table: "wf_hi_task", Column: "ended_at", Precision: intPtr(3)},
}
low, missing = evaluateSchemaPrecision(expected, nullPrecision)
require.Empty(t, low)
require.Equal(t, []string{"wf_task.ended_at"}, missing)
}
// sqlite 等无精度概念的方言直接跳过(引擎自测环境就是 sqlite)。
func TestSchemaPrecisionGuard_SQLiteSkipped(t *testing.T) {
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
require.NoError(t, err)
require.NoError(t, NewSchemaPrecisionGuard(db).Validate())
}
// db 为空(单测装配无库引擎)时探测跳过。
func TestSchemaPrecisionGuard_NilDB(t *testing.T) {
require.NoError(t, NewSchemaPrecisionGuard(nil).Validate())
}
+10 -6
View File
@@ -702,7 +702,7 @@ func checkRecallPath(chain *types.RuleChain, fromDefKey string) error {
}
// buildRecalledTask 从 T 的快照重建收回人的待审任务。到期时间沿用 T(与加签
// 继承同口径);variables 剔除 approved/comment 约定键——Complete 会消费它们,
// 继承一致);variables 剔除 approved/comment 约定键——Complete 会消费它们,
// 残留会让重建任务带着旧投票结果被静默自动通过;_sequentialAssignees 缓存
// 保留,顺序会签推进依赖。
func buildRecalledTask(gen IDGenerator, t *model.WfTask, userID, username string, now time.Time) *model.WfTask {
@@ -787,14 +787,15 @@ func stripReservedMarks(vars *string) *string {
}
// hasProxyMark 任务变量是否带管理员代审标记(ProxyAudit 写入 proxy_operator)。
// 解析失败按无标记处理:其余守卫照常兜底,不让损坏数据卡死正常收回。
// 解析失败按带标记处理:变量损坏时无法证明未被代审,放行收回会覆盖代审事实。
// 变量为空即未代审(ProxyAudit 必写标记),不受影响。
func hasProxyMark(t *model.WfTask) bool {
if t == nil || t.Variables == nil || *t.Variables == "" {
return false
}
m, err := ParseVariablesJSON(t.Variables)
if err != nil {
return false
return true
}
if v, ok := m[constants.VarsProxyOperator].(string); ok {
return v != ""
@@ -827,12 +828,15 @@ func listAllInstanceTasksTx(ctx context.Context, taskDAO *dao.TaskDAO, instanceI
}
}
// recallCountExhausted 实例累计收回次数是否已达上限。解析失败按未达上限处理:
// 损坏变量不该把正常收回卡死。
// recallCountExhausted 实例累计收回次数是否已达上限。解析失败按已达上限处理,
// 防损坏变量绕过收回上限;变量为空即从未收回,放行。
func recallCountExhausted(vars *string) bool {
if vars == nil || *vars == "" {
return false
}
m, err := ParseVariablesJSON(vars)
if err != nil {
return false
return true
}
if v, ok := m[constants.VarsRecallCount].(float64); ok {
return int(v) >= constants.MaxRecallCountPerInstance
+20 -1
View File
@@ -1064,7 +1064,7 @@ func TestRecallVarHelpers(t *testing.T) {
}
require.True(t, recallCountExhausted(bumped))
require.False(t, recallCountExhausted(secFixStrPtr(vars)))
require.False(t, recallCountExhausted(secFixStrPtr("not-json")), "损坏变量按未达上限处理")
require.True(t, recallCountExhausted(secFixStrPtr("not-json")), "损坏变量按已达上限处理")
stripped := stripCountersignMergedKeys(secFixStrPtr(`{"approved":false,"k":"v"}`))
require.Contains(t, *stripped, `"k":"v"`)
@@ -1116,3 +1116,22 @@ func TestCheckRecallPath_AutomationOnAnyBranchRejected(t *testing.T) {
err := checkRecallPath(chain, "t")
require.Error(t, err, "任一分支走向上有自动化节点都应拒绝")
}
// ---- 保留键解析 fail-closed ----
// 变量损坏时无法证明「未代审/未达上限」,按带标记/已达上限处理;空变量不受影响。
func TestRecallReservedVarGuardsFailClosed(t *testing.T) {
corrupt := "{not-json"
marked := `{"proxy_operator":"admin"}`
unmarked := `{"amount":100}`
counted := `{"_recallCount":1}`
require.True(t, hasProxyMark(&model.WfTask{Variables: &corrupt}), "损坏变量按带代审标记处理,收回被拦")
require.True(t, hasProxyMark(&model.WfTask{Variables: &marked}))
require.False(t, hasProxyMark(&model.WfTask{Variables: &unmarked}))
require.False(t, hasProxyMark(&model.WfTask{}))
require.False(t, hasProxyMark(nil))
require.True(t, recallCountExhausted(&corrupt), "损坏变量按已达上限处理,收回被拦")
require.False(t, recallCountExhausted(&counted))
require.False(t, recallCountExhausted(nil))
require.False(t, recallCountExhausted(secFixStrPtr("{}")))
}
+7 -1
View File
@@ -282,12 +282,18 @@ func (e *WorkflowEngineImpl) Start(ctx context.Context) error {
// 装配期探测租户归属校验能力:宿主 IdentityService 未实现 TenantMembershipChecker
// 时,转派目标/startProcess 发起人/ccTask 抄送人的跨租户校验整体跳过。默认记一条
// 启动告警;strict_tenant_membership_check=true 时拒绝启动(fail-fast)。
// 启动告警;strict_tenant_membership_check=true 时拒绝启动。
// 详见 operator_authz.go 的 TenantMembershipGuard.Validate。
if err := NewTenantMembershipGuard(e.identityService).Validate(e.config.StrictTenantMembershipCheck); err != nil {
return fmt.Errorf("workflow engine '%s': %w", e.name, err)
}
// 装配期校验引擎时序依赖的时间列精度(wf_task/wf_hi_task):秒级列上收回
// 守卫无法分序,探到即拒绝启动。见 schema_guard.go。
if err := NewSchemaPrecisionGuard(e.db).Validate(); err != nil {
return fmt.Errorf("workflow engine '%s': %w", e.name, err)
}
// 初始化Locker(如果未设置)
if e.locker == nil {
e.locker = lock.NewLocalLock()