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

多个package时,进行Package.UpdatePackageVersionAsync会产生第二个package调用时直接使用FallbackURL #156

Closed
ConnorSin opened this issue Sep 5, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ConnorSin
Copy link

查看了源码发现下面文件因为RequestCount是static的,第一包请求时调用GetPackageVersionRequestURL返回了正确的地址,轮到第二个包请求时就会直接返回了FallbackURL

`

using System.IO;

namespace YooAsset
{
internal class QueryRemotePackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
DownloadPackageVersion,
Done,
}

	private static int RequestCount = 0;
	private readonly IRemoteServices _remoteServices;
	private readonly string _packageName;
	private readonly bool _appendTimeTicks;
	private readonly int _timeout;
	private UnityWebDataRequester _downloader;
	private ESteps _steps = ESteps.None;

	/// <summary>
	/// 包裹版本
	/// </summary>
	public string PackageVersion { private set; get; }
	

	public QueryRemotePackageVersionOperation(IRemoteServices remoteServices, string packageName, bool appendTimeTicks, int timeout)
	{
		_remoteServices = remoteServices;
		_packageName = packageName;
		_appendTimeTicks = appendTimeTicks;
		_timeout = timeout;
	}
	internal override void Start()
	{
		RequestCount++;
		_steps = ESteps.DownloadPackageVersion;
	}
	internal override void Update()
	{
		if (_steps == ESteps.None || _steps == ESteps.Done)
			return;

		if (_steps == ESteps.DownloadPackageVersion)
		{
			if (_downloader == null)
			{
				string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
				string webURL = GetPackageVersionRequestURL(fileName);
				YooLogger.Log($"Beginning to request package version : {webURL}");
				_downloader = new UnityWebDataRequester();
				_downloader.SendRequest(webURL, _timeout);
			}

			Progress = _downloader.Progress();
			if (_downloader.IsDone() == false)
				return;

			if (_downloader.HasError())
			{
				_steps = ESteps.Done;
				Status = EOperationStatus.Failed;
				Error = _downloader.GetError();
			}
			else
			{
				PackageVersion = _downloader.GetText();
				if (string.IsNullOrEmpty(PackageVersion))
				{
					_steps = ESteps.Done;
					Status = EOperationStatus.Failed;
					Error = $"Remote package version is empty : {_downloader.URL}";
				}
				else
				{
					_steps = ESteps.Done;
					Status = EOperationStatus.Succeed;
				}
			}

			_downloader.Dispose();
		}
	}

	private string GetPackageVersionRequestURL(string fileName)
	{
		string url;

		// 轮流返回请求地址
		if (RequestCount % 2 == 0)
			url = _remoteServices.GetRemoteFallbackURL(fileName);
		else
			url = _remoteServices.GetRemoteMainURL(fileName);

		// 在URL末尾添加时间戳
		if (_appendTimeTicks)
			return $"{url}?{System.DateTime.UtcNow.Ticks}";
		else
			return url;
	}
}

}

`

@gmhevinci gmhevinci added the bug Something isn't working label Sep 5, 2023
@sunny352
Copy link

本质上应该是图省事没有做重试逻辑导致的,这种写法有四处,需要在这4个地方添加重试

@gmhevinci
Copy link
Collaborator

fixed 49b1889

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

Successfully merging a pull request may close this issue.

3 participants