Ubuntu 18.04 freezes when I click on an additional gaming mouse button

I have problems with Ubuntu 18.04 and the Logitech g300s model. I am not sure if this problem affects other mouse models.

To test this, it's easy:

Open the terminal, click on additional buttons with the mouse. Ubuntu freezes for a few seconds, where the mouse pointer still works. If you enter something using the keyboard, only what you typed after freezing is displayed. This means that the application freezes the inputs during the process.

I've been browsing the forums all around and the only thing I've found is a couple of users who are referring to some problems with autosuspend, but this is not the same problem here.

I also found a thread that concerns the topic for Ubuntu 17.04 without a solution.

Note that the mouse works fine with Ubuntu 14.04.