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

V3.15.1 中忽略Alias Log的方式导致空指针panic #4093

Closed
4 tasks done
Sansui233 opened this issue Apr 8, 2023 · 2 comments
Closed
4 tasks done

V3.15.1 中忽略Alias Log的方式导致空指针panic #4093

Sansui233 opened this issue Apr 8, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Sansui233
Copy link

Sansui233 commented Apr 8, 2023

Please make sure of the following things

  • I have read the documentation.
  • I'm sure there are no duplicate issues or discussions.
  • I'm sure it's due to alist and not something else(such as Dependencies or Operational).
  • I'm sure I'm using the latest version

Alist Version / Alist 版本

v3.15.1

Driver used / 使用的存储驱动

OnedriveApp

Describe the bug / 问题描述

#4054 的fix中,Get增加了NoLog参数,当设置为true时导致了 fs.Get 时返回空指针。( 并且 #4054 的问题没有得到完全的解决 )

//fs.go
func Get(ctx context.Context, path string, args *GetArgs) (model.Obj, error) {
	res, err := get(ctx, path) // res为nil,error不为空
	if err != nil && !args.NoLog {
		log.Errorf("failed get %s: %+v", path, err)
		return nil, err
	}
	return res, nil // 实际返回值为nil, nil
}

于是alias在处理时会触发空指针的错误

// drivers/alias/util.go
func (d *Alias) get(ctx context.Context, path string, dst, sub string) (model.Obj, error) {
	obj, err := fs.Get(ctx, stdpath.Join(dst, sub), &fs.GetArgs{NoLog: true}) //
	if err != nil {
		return nil, err
	}
	return &model.Object{
		Path:     path,
		Name:     obj.GetName(), // obj为nil,空指针错误由gin recover,直接中断掉所有后续操作。页面显示500。
		Size:     obj.GetSize(),
		Modified: obj.ModTime(),
		IsFolder: obj.IsDir(),
	}, nil
}

页面直接Crash。
image

以上错误发生于Alias的查找的第一个父级目录为空时。当第一个父级目录的子文件夹存在,但第二个父级目录的相应子文件夹不存在时,Web页面显示正常,但依然出现 #4054 所述的objectNotFound问题,这个错误是由 List 抛出的,走alias/util中的 getRootAndPath,而 v3.15.1 中的改的是fs中的GetgetRootAndPath不调用这个方法,所以没有改到这个问题

�[31mERRO�[0m[2023-04-08 23:38:39] failed list /OneDrive/Resource/10_书: object not found
github.com/alist-org/alist/v3/internal/op.Get
	C:/Users/lingn/git/alist/internal/op/fs.go:220
github.com/alist-org/alist/v3/internal/op.GetUnwrap
	C:/Users/lingn/git/alist/internal/op/fs.go:224
github.com/alist-org/alist/v3/internal/op.List
	C:/Users/lingn/git/alist/internal/op/fs.go:109
github.com/alist-org/alist/v3/internal/fs.list
	C:/Users/lingn/git/alist/internal/fs/list.go:25
github.com/alist-org/alist/v3/internal/fs.List
	C:/Users/lingn/git/alist/internal/fs/fs.go:22
github.com/alist-org/alist/v3/drivers/alias.(*Alias).list
	C:/Users/lingn/git/alist/drivers/alias/util.go:68
github.com/alist-org/alist/v3/drivers/alias.(*Alias).List
	C:/Users/lingn/git/alist/drivers/alias/driver.go:91

对于空指针问题的解决方式,大概是

// drivers/alias/util.go get中加对obj的判断
	if obj == nil {
		return nil, nil
	}

并且 fs/fs.goop/fs.go 中均要考虑 object 为 nil 的相关操作,但好像不那么优雅……我自己感觉的话 fs 中的 Get 不用加 NoLog 重构,只是需要在考虑 Alias 里怎么去处理Get之后objNotFound的Error……但也只是我的想法,因为这个问题的处理方式不只一种有可能涉及到挺核心的东西我也不太清楚作者的处理方式不好PR……

然后Alias里面的getRootPath也是要改的……

Reproduction / 复现链接

本地Debug无公开链接

Logs / 日志

空指针错误
image

#4054 中描述的问题依然存在的日志
image

@Sansui233 Sansui233 added the bug Something isn't working label Apr 8, 2023
@xhofe xhofe closed this as completed in c0a6bee Apr 9, 2023
@xhofe
Copy link
Collaborator

xhofe commented Apr 9, 2023

现在应该可以了,可以测试一下:https://github.com/alist-org/alist/actions/runs/4649099015

@Sansui233
Copy link
Author

现在应该可以了,可以测试一下:https://github.com/alist-org/alist/actions/runs/4649099015

空指针解决了~👍

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

No branches or pull requests

2 participants