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

Dropped requests from middleware remain in 'Started' state for AsyncFunctions. #77

Open
niko284 opened this issue Sep 4, 2022 · 3 comments

Comments

@niko284
Copy link

niko284 commented Sep 4, 2022

When calling the server with a ServerAsyncFunction, there's a possibility that your middleware may not propagate your request and finish it. For a client that is awaiting the promise's fate, the promise never settles.

This can be reproduced by making a middleware that rejects all requests and hooking a :finally() method to your promise. It will never reach it.

@Vorlias
Copy link
Member

Vorlias commented Sep 10, 2022

What version of Net are you using, perchance?

@Vorlias
Copy link
Member

Vorlias commented Sep 10, 2022

Also do you have an example of a middleware which triggers this behaviour + some example client call code to go with it?

@niko284
Copy link
Author

niko284 commented Sep 10, 2022

I am currently on vorlias/[email protected] on Wally. Here is an example::

Client sided code:

UseItem:CallServerAsync()
	:andThen(function(networkResponse: Types.NetworkResponse)
		if networkResponse.Success == false then
			warn(networkResponse.Response)
			-- Let's rollback the state, so the item is back in the inventory, since the server didn't accept it.
			props.addItem(item)
		end
	end)
	:finally(function()
		print("settled")
	end)

Server sided middleware:

-- Deserializer
-- August 27th, 2022
-- Nick

-- // Variables \\

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Constants = ReplicatedStorage.constants
local Types = require(Constants.Types)

local Deserializer = {}

local function DeserializerMiddleware(deserializers: { Types.Serializer })
	return function(next, _instance)
		return function(player, ...)
			return error("no")
		end
	end
end

Deserializer.__call = function(_, ...)
	return DeserializerMiddleware(...)
end

return setmetatable({}, Deserializer)

An error is always returned by my middleware and next() is never called, for an easy repro case. My :finally() method that is attached to my promise is never called, and 'settled' never prints.

Here is the output to a UseItem call:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants