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

[BUG FIX] Config listener doesn't execute when querying result is config doesn't exist #712

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clients/config_client/config_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,17 @@ func (client *ConfigClient) refreshContentAndCheck(cacheData cacheData, notify b
cacheData.group, cacheData.tenant)
return
}
if configQueryResponse != nil && configQueryResponse.Response != nil && !configQueryResponse.IsSuccess() {
if configQueryResponse != nil && configQueryResponse.Response != nil &&
!configQueryResponse.IsSuccess() && configQueryResponse.GetErrorCode() != int(rpc_response.ConfigNotFound) {
logger.Errorf("refresh cached config from server error:%v, dataId=%s, group=%s", configQueryResponse.GetMessage(),
cacheData.dataId, cacheData.group)
return
}
cacheData.content = configQueryResponse.Content
cacheData.contentType = configQueryResponse.ContentType
cacheData.encryptedDataKey = configQueryResponse.EncryptedDataKey
if len(strings.TrimSpace(configQueryResponse.ContentType)) > 0 {
cacheData.contentType = configQueryResponse.ContentType
}
if notify {
logger.Infof("[config_rpc_client] [data-received] dataId=%s, group=%s, tenant=%s, md5=%s, content=%s, type=%s",
cacheData.dataId, cacheData.group, cacheData.tenant, cacheData.md5,
Expand Down
4 changes: 2 additions & 2 deletions clients/config_client/config_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func (cp *ConfigProxy) queryConfig(dataId, group, tenant string, timeout uint64,
return response, nil
}

if response.GetErrorCode() == 300 {
if response.GetErrorCode() == int(rpc_response.ConfigNotFound) {
cache.WriteConfigToFile(cacheKey, cp.clientConfig.CacheDir, "")
cache.WriteEncryptedDataKeyToFile(cacheKey, cp.clientConfig.CacheDir, "")
return response, nil
}

if response.GetErrorCode() == 400 {
if response.GetErrorCode() == int(rpc_response.ConfigQueryConflict) {
logger.Errorf(
"[config_rpc_client] [sub-server-error] get server config being modified concurrently, dataId=%s, group=%s, "+
"tenant=%s", dataId, group, tenant)
Expand Down
2 changes: 1 addition & 1 deletion common/remote/rpc/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func serverCheck(client nacos_grpc_service.RequestClient) (rpc_response.IRespons
return nil, err
}
// check if the server is ready, if not, wait 1 second and try again
if response.GetErrorCode() >= 300 && response.GetErrorCode() < 400 {
if response.GetErrorCode() >= int(rpc_response.ConfigNotFound) && response.GetErrorCode() < int(rpc_response.ConfigQueryConflict) {
// if we wait 30 second, but the server is not ready,then throw this error
if i == 30 {
return nil, errors.New("the nacos server is not ready to work in 30 seconds, connect to server failed")
Expand Down
2 changes: 1 addition & 1 deletion common/remote/rpc/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (r *RpcClient) sendHealthCheck() bool {
// when client request immediately after the nacos server starts, the server may not ready to serve new request
// the server will return code 3xx, tell the client to retry after a while
// this situation, just return true,because the healthCheck will start again after 5 seconds
if response.GetErrorCode() >= 300 && response.GetErrorCode() < 400 {
if response.GetErrorCode() >= int(rpc_response.ConfigNotFound) && response.GetErrorCode() < int(rpc_response.ConfigQueryConflict) {
return true
}
return false
Expand Down
7 changes: 7 additions & 0 deletions common/remote/rpc/rpc_response/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ const (

ResponseSuccessField = "success"
)

type ResponseErrorCode int

const (
ConfigNotFound ResponseErrorCode = 300
ConfigQueryConflict ResponseErrorCode = 400
)
Loading