Cities: Skylines game frequently crashes

The Cities: Skylines game keeps objects in memory even if the object is not used. Even a 16GB system can crash frequently if the memory usage is not managed.

“Oops! The game crashed

The memory usage is high, even when the map is not too complex.

Enable enough Virtual Memory

Make sure Windows has enough Virtual Memory configured. I have set up 4096 MB minimum and maximum Virtual Memory for my 16 GB Toshiba laptop.

Install the Loading Screen mod

This page explains the issue and how to solve the problem: https://steamcommunity.com/app/255710/discussions/0/1488866180604646672/

This is the summary of the steps you can take to stabilize the game on your computer

Get jstack and other Java utilities without installing the Java JDK

  • Open a Windows command prompt
  • Create a directory for the volume and start the openjdk container
md c:\windows\temp\openjdk
docker run -it --rm -v c:\windows\temp\openjdk:c:\temp openjdk:8
  • In the Java container copy the contents of the Java bin directory to the mapped volume
cd openjdk-8\bin
copy *.* c:\temp

Docker in Windows 10 via VMware Fusion on a MacBook Pro

To run Windows Docker containers on your Macintosh computer, use the following setup. This will introduce a performance hit, because you run virtualization in virtualization.

Besides the usual setup process, you need to enable hypervisor applications to avoid the error

Error response from daemon: container … encountered an error during CreateContainer: failure in a Windows system call:  No hypervisor is present on this system

  • Install VMware Fusion on your MacBook Pro
  • Create a Windows 10 virtual machine
  • Open the Settings of the Windows 10 virtual machine
  • Select Processors & Memory
  • In the Advanced region check Enable hypervisor applications in this virtual machine

Turn off the GDPR cookie notification in a dotnet core MVC web application

The dotnet core MVC web application template adds the GDPR cookie acceptance message to the header of the page template. When the site is hosted with HTTP the accept button does not clear the message resulting an infinite loop, when the user cannot log in and the site continuously asks for the acceptance.

When the site is hosted in a Docker container it is also simpler to instal the SSL certificate on the load balancer and host the site with HTTP on port 80.

We use cookies. To be able to use this site please click the Accept button.

To remove the feature delete the

<partial name="_CookieConsentPartial" />

line from the Views\Shared\Layout.cshtml file.

Without the acknowledgement the dotnet core framework will not save any non essential cookies in the browser, so the session state will stop working.

To tell the dotnet core framework, that the application does not require the user to allow the saving of the cookies set the value of CheckConsentNeeded to false in the ConfigureServices() method, services.Configure<CookiePolicyOptions> { section

options.CheckConsentNeeded = context => false;

To make sure the session cookie is always saved even if the GDPR confirmation is enabled, declare it to essential in the ConfigureServices() method, services.AddSession(options => { section

options.Cookie.IsEssential = true;

Read the database connection string and other secrets from environment variables

It is not good practice to store secrets in the source code repository. The sample C# dotnet core application code stores the database connection string in the appsettings.json file which eventually will be pushed into GitHub. To follow the Twelve-Factor App methodology, store the configuration values in environment variables and load them runtime. This method enables your application to run in a Docker container and in a Kubernetes pod.

If the connection string is not specified, we get the error message

System.ArgumentNullException: ‘Value cannot be null.
Parameter name: connectionString’

To read the connection string from an environment variable

Add the builders to the Startup.cs file

       public Startup(IConfiguration configuration, IHostingEnvironment env)
        {
            Configuration = configuration;
            Env = env;

            // Read the connection string from the "ASPNETCORE_ConnectionStrings:DefaultConnection" environment variable
            // RESTART Visual Studio if you add or edit environment variables for the change to take effect.
            var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            // This one needs to be last for the environment variables to have the highest priority
            builder.AddEnvironmentVariables("ASPNETCORE_");
            Configuration = builder.Build();
        }

Create the ASPNETCORE_ConnectionStrings__DefaultConnection environment variable. The double underscore will be converted to a colon ( : ) . This variable name works on Windows, and also in Linux where the environment variable name cannot contain colons.

Server=MY_SERVER_URL;Port=5432;Database=MY_DATABASE;Username=MY_USER;Password=MY_PASSWORD

IMPORTANT: If you add or change an environment variable, restart Visual Studio for the change to take effect. It is not enough to restart the application.

Mount NFS volume from macOS

When we try to mount an NFS with

docker run --rm -i -v MY_MOUNT:/data alpine

from macOS we get the error message:

docker: Error response from daemon: error while mounting volume ‘/var/lib/docker/volumes/…/_data’: failed to mount local volume: mount :/data:/var/lib/docker/volumes/…/_data, data: addr=…,vers=4: operation not permitted.

or

docker: Error response from daemon: error while mounting volume ‘/var/lib/docker/volumes/…/_data’: failed to mount local volume: mount :/data:/var/lib/docker/volumes/…/_data, data: addr=…,vers=4: connection refused.

To be able to mount the volume from macOS, use the insecure option in /etc/exports

MY_MOUNT 10.0.0.0/8(rw,sync,no_root_squash,no_all_squash,insecure)

ERROR: column “…” does not exist

PostgreSQL internally converts all column and table names to lowercase when executing the SQL query.

If the column or table name contains uppercase letters, we need to use double quotes to be able to reference them.

When we get the error message

ERROR: column “username” does not exist

select * from public.”AspNetUsers” where UserName = ‘… ^

HINT: Perhaps you meant to reference the column “AspNetUsers.UserName”. SQL state: 42703

The first line of the error message shows, that PostgreSQL internally converted UserName to username. To be able to reference the column, use double-quotes. If you reference the table name too, don’t copy the hint, make sure the table and column names are separate strings in double-quotes with a period between them.

select *  from public."AspNetUsers" where "AspNetUsers"."UserName" = 'MY_VALUE';

PostgreSQL management tools

Install postgresql

The postgresql package contains the PostgreSQL utilities: psql, pg_dump

On macOS

 brew install postgresql

Install pgAdmin

pgAdmin is a browser based database management tool for PosgtreSQL databases.

Download

Install

On macOS

  • Double click the downloaded file
  • Accept the license agreement
  • Drag the application into the Applications folder

Start pgAdmin

On macOS

  • Start the pgAdmin application from the Launchpad. The application runs in a browser window.

Install the pgcli command line utility

On macOS

brew install pgcli

Using pgcli

pgcli is a wrapper of postgresql with limited command set to enable testers and support staff to monitor PostgreSQL databases

Start pgcli with

PGPASSWORD=MY_ADMIN_PASSWORD pgcli -h MY_SERVER_URL -U MY_USERNAME -d MY_DATABASE_NAME

To see the help on the pgcli commands

\?

syntax error, unexpected tLABEL in Chef Test Kitchen

During the test of a Chef recipe that contains a template we may encounter the error message

syntax error, unexpected tLABEL
MY_KEY: MY_VALUE

Make sure there is no white space between the keyword variables and the opening parenthesis in the template definition:

template "MY_FILE" do
  source 'MY_SOURCE'
  variables(
    MY_KEY: MY_VALUE
  )
end

How to remove all Docker containers and images from the host

Docker images are stored on the host to launch as fast as possible. The drawback is, Docker can fill the hard drive with unused images. A recent possible bug in Docker caused the accumulation of unused, unreferenced images on the host. To delete all Docker containers and images, use these commands in the terminal

Get the base line

# Get the free disk space
df -h

# List the running containers
docker ps

# List all containers
docker ps -a

# List the Docker images
docker images

Gentle clean up

  • all stopped containers
  • all networks not used by at least one container
  • all dangling images
  • all dangling build cache
docker system prune

All unused images and stopped containers

docker rm $(docker ps -qa); docker rmi -f $(docker images -q);yes | docker system prune

Deep cleaning

This will stop and delete ALL containers and images on the computer !!!

# Stop all running containers
docker stop $(docker ps -q)

# Remove all stopped containers
docker rm $(docker ps -qa)

# Remove all unused Docker images
docker rmi -f $(docker images -q)

# A final clean
docker system prune