# [Known Issues] TiCDC v6.1, 开启 syncpoint 功能，启动 changfeed 报错 “panic  runtime error  invalid memory address or nil pointer dereference“

## Key Words

TiCDC, sync point, sync_point, invalid memory address or nil pointer dereference

## Description

TiDB 通过 TiCDC 将数据同步到下游 TiDB，启动 changfeed task 时候报错 panic，导致初始化 TiCDC task 失败。

关键报错日志如下：

```golang
[2022/07/19 16:07:20.715 +05:30] [INFO] [client.go:241] ["WatchWithChan exited"] [role=owner]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x2ebf451]

goroutine 621 [running]:
github.com/pingcap/tiflow/cdc/owner.(\*ddlSinkImpl).emitSyncPoint(0xc00056ca10, 0x4122eb8, 0xc00011cf00, 0x608539923e80454, 0x20113a80, 0xeda683738)
    github.com/pingcap/tiflow/cdc/owner/ddl_sink.go:226 +0x71
github.com/pingcap/tiflow/cdc/owner.(\*changefeed).handleBarrier(0xc00106bd40, 0x4122eb8, 0xc00011cf00, 0x608539923e80454, 0x0, 0x0)
    github.com/pingcap/tiflow/cdc/owner/changefeed.go:475 +0x1bc
github.com/pingcap/tiflow/cdc/owner.(\*changefeed).tick(0xc00106bd40, 0x4122eb8, 0xc00011cf00, 0xc001f36f60, 0xc001f34b10, 0x0, 0x0)
    github.com/pingcap/tiflow/cdc/owner/changefeed.go:179 +0x24d
github.com/pingcap/tiflow/cdc/owner.(\*changefeed).Tick(0xc00106bd40, 0x4122dc8, 0xc00011ced0, 0xc001f36f60, 0xc001f34b10)
    github.com/pingcap/tiflow/cdc/owner/changefeed.go:118 +0x149
```

## Root Cause

sync-point-enabled 参数：TiCDC 默认同步模式是最终一致，可以通过开启这个参数，定期刷新 checkpoint，并在下游 TiDB 集群提供一个基于某个指定的 checkpoint tso 一致性读的功能。

当 TiCDC  task 任务启动时候，并开启 syncpoint 功能，DDL sink 初始化阶段，ddl sink 的 syncpoint 赋值和调用在两个不同的 goroutine 中，代码模块 ddlSinkImpl.syncPointStore，如果调用发生在赋值之前，那么就会发生空指针错误。

Github issue: [https://github.com/pingcap/tiflow/issues/4934](https://github.com/pingcap/tiflow/issues/4934)

## Diagnostic Steps

1. 收集 TiCDC 对应 Changefeed 的初始化日志；
2. 搜索关键字 “[github.com/pingcap/tiflow/cdc/owner.(\*ddlSinkImpl).emitSyncPoint](http://github.com/pingcap/tiflow/cdc/owner.(*ddlSinkImpl).emitSyncPoint)“  和 “panic: runtime error: invalid memory address or nil pointer dereference“
3. 通过 Github issue 确认报错是否匹配；
4. 定位到是否该 bug 导致。

## Resolution

待功能 GA 后使用

## Workaround

< 6.1 版本，启动 changefeed 时候，默认不启动该参数配置，既 sync-point-enabled = false

## Affected Versions

TiCDC <= v6.1