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

HeaderByNumber sometimes returns nil header and nil error together. #968

Closed
Yashk767 opened this issue Oct 10, 2022 · 2 comments · Fixed by #974
Closed

HeaderByNumber sometimes returns nil header and nil error together. #968

Yashk767 opened this issue Oct 10, 2022 · 2 comments · Fixed by #974
Assignees
Labels
bug Something isn't working critical

Comments

@Yashk767
Copy link
Contributor

oracle-node version: v1.3.0-alpha

Describe the bug

Ideally HeaderByNumber returns nil header only when there is any error (i.e. error is not nil).
But sometimes it returns nil header and nil error together.

The error check during error handling is false as the error is nil , so fetching the returned nil header results in panic: runtime error: invalid memory address or nil pointer dereference

@Yashk767 Yashk767 self-assigned this Oct 10, 2022
@Yashk767 Yashk767 added bug Something isn't working critical labels Oct 10, 2022
@Yashk767
Copy link
Contributor Author

func CheckIfAnyError(result []reflect.Value) error {
	rpcError := errors.New("RPC Timeout error")
	if result == nil {
		return rpcError
	}

	errorIndexInReturnedValues := -1
	for i := range result {
		returnedValue := result[i]
		if reflect.TypeOf(returnedValue.Interface()) == reflect.TypeOf(rpcError) {
			errorIndexInReturnedValues = i
		}
	}
	if errorIndexInReturnedValues == -1 {
		return nil
	}
	returnedError := result[errorIndexInReturnedValues].Interface()
	if returnedError != nil {
		return returnedError.(error)
	}
	return nil
}

@Yashk767
Copy link
Contributor Author

Yashk767 commented Oct 11, 2022

In function CheckIfAnyError() we iterate over the returned values of a function and check for error.
We compare the data type of errors.New("RPC Timeout error") with returned value, if it's same we consider that as a returned error and update errorIndexInReturnedValues.

The problem here is reflect.TypeOf(errors.New("RPC Timeout error")) returns *errors.errorString,
while taking in consideration any RPC error e.g

ERROR: Post "https://staging-v2.skalenodes.com/v1/whispering-turais": dial tcp: lookup staging-v2.skalenodes.com: no such host

It's of type *url.Error. which is not same as data type of our custom rpc error.

So even when there is an error returned by a function , CheckIfAnyError() says there is no error due to incorrect comparison of data types.

@ashish10677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants