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

Update gutil_dump.go #2305

Closed
wants to merge 1 commit into from
Closed

Conversation

brick-carrier-fan
Copy link

Solve the panic: reflect: call of reflect.Value.Type on zero Value [recovered] The reason for this is the circular reference itself

Solve the panic: reflect: call of reflect.Value.Type on zero Value [recovered]
The reason for this is the circular reference itself
@brick-carrier-fan
Copy link
Author

brick-carrier-fan commented Nov 17, 2022

it likes

type Abc struct {
		ab int
		//bc BC
		cd *Abc
	}
	
	abc := Abc{ab: 3}
	abc.cd = &abc
	g.Dump(abc)

output:
panic: reflect: call of reflect.Value.Type on zero Value

@@ -110,9 +110,12 @@ func doDump(value interface{}, indent string, buffer *bytes.Buffer, option doDum
}
var (
reflectKind = reflectValue.Kind()
reflectTypeName = reflectValue.Type().String()
reflectTypeName = "invalid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may check the reflectValue at line 107:

// Double check nil value.
if value == nil || reflectValue.IsNil() || !reflectValue.IsValid() {
	buffer.WriteString(`<nil>`)
	return
}

Copy link
Author

@brick-carrier-fan brick-carrier-fan Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried your way of checking the reflectValue, and it brings the same mistake.
Not available to check reflectValue with IsNil().
The method I submitted is available.
I apologize for my poor English.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brick-carrier-fan OK, then try this:

// Double check nil value.
if value == nil || !reflectValue.IsValid() || (reflectValue.Kind() == reflect.Ptr && reflectValue.IsNil()) {
	buffer.WriteString(`<nil>`)
	return
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,buffer will go to get infinitely bigger,then get OOM panic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,buffer will go to get infinitely bigger,then get OOM panic

Any question carrying on this PR?

@gqcn
Copy link
Member

gqcn commented Nov 17, 2022

@brick-carrier-fan Please add UT case for this issue, too.

@gqcn gqcn added the awesome It's awesome! We keep watching. label Nov 17, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2022

Codecov Report

Base: 78.17% // Head: 78.15% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (126ccb9) compared to base (14d2d74).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2305      +/-   ##
==========================================
- Coverage   78.17%   78.15%   -0.02%     
==========================================
  Files         584      584              
  Lines       48535    48538       +3     
==========================================
- Hits        37942    37937       -5     
- Misses       8579     8584       +5     
- Partials     2014     2017       +3     
Flag Coverage Δ
go-1.15-386 78.15% <100.00%> (-0.02%) ⬇️
go-1.15-amd64 78.18% <100.00%> (+0.02%) ⬆️
go-1.16-386 78.19% <100.00%> (-0.02%) ⬇️
go-1.16-amd64 78.16% <100.00%> (-0.01%) ⬇️
go-1.17-386 78.16% <100.00%> (-0.04%) ⬇️
go-1.17-amd64 78.18% <100.00%> (-0.02%) ⬇️
go-1.18-386 78.07% <100.00%> (-0.04%) ⬇️
go-1.18-amd64 78.12% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
util/gutil/gutil_dump.go 91.95% <100.00%> (+0.07%) ⬆️
os/gcache/gcache_adapter_memory_lru.go 89.13% <0.00%> (-8.70%) ⬇️
os/gfpool/gfpool_file.go 65.71% <0.00%> (-2.86%) ⬇️
os/glog/glog_logger_rotate.go 63.34% <0.00%> (-1.36%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gqcn gqcn mentioned this pull request Nov 21, 2022
@@ -110,9 +110,12 @@ func doDump(value interface{}, indent string, buffer *bytes.Buffer, option doDum
}
var (
reflectKind = reflectValue.Kind()
reflectTypeName = reflectValue.Type().String()
reflectTypeName = "invalid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brick-carrier-fan OK, then try this:

// Double check nil value.
if value == nil || !reflectValue.IsValid() || (reflectValue.Kind() == reflect.Ptr && reflectValue.IsNil()) {
	buffer.WriteString(`<nil>`)
	return
}

@@ -110,9 +110,12 @@ func doDump(value interface{}, indent string, buffer *bytes.Buffer, option doDum
}
var (
reflectKind = reflectValue.Kind()
reflectTypeName = reflectValue.Type().String()
reflectTypeName = "invalid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,buffer will go to get infinitely bigger,then get OOM panic

Any question carrying on this PR?

@gqcn
Copy link
Member

gqcn commented Dec 20, 2022

@brick-carrier-fan I fix this in #2367

@gqcn gqcn closed this Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awesome It's awesome! We keep watching.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants